/* Approved PXLTAB menu contract shared by User UI and Debug UI.
   Native selects remain the data source; this layer changes presentation only. */

/* Shared filter-action alignment. Pair the invisible label with the visible
   field labels so Clear filters always sits on the same control baseline. */
.pxds-filter-row > label {
  margin: 0;
}

.pxds-filter-action {
  min-width: 0;
  display: grid;
  align-self: end;
  gap: 6px;
}

.pxds-filter-action > span {
  visibility: hidden;
}

.pxds-filter-action > button {
  min-height: 38px;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-native-select {
  display: none !important;
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  white-space: nowrap !important;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select {
  position: relative;
  min-width: 0;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select.is-open {
  z-index: 120;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger {
  width: 100%;
  min-height: 35px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--pxds-border-strong);
  border-radius: 7px;
  color: var(--pxds-text-subtle);
  background: var(--pxds-surface-1);
  box-shadow: none;
  cursor: pointer;
  text-align: left;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  transition:
    border-color var(--pxds-motion-fast) ease,
    box-shadow var(--pxds-motion-fast) ease,
    background var(--pxds-motion-fast) ease,
    color var(--pxds-motion-fast) ease;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-filter-row .pxds-select-trigger {
  min-height: 38px;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--pxds-brand) 72%, var(--pxds-border-strong));
}

html[data-theme="light"] :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger:not(.has-value):hover:not(:disabled) {
  color: var(--pxds-text);
  background: var(--pxds-hover-surface);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger:focus-visible {
  outline: 2px solid var(--pxds-brand);
  outline-offset: 2px;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger.has-value {
  border-color: transparent;
  color: #ffffff;
  background: var(--pxds-brand-fill);
  font-weight: 700;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-field:is(.is-required-missing, .is-invalid) .pxds-select-trigger,
:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger[aria-invalid="true"] {
  border-color: rgba(255, 92, 101, 0.84);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-chevron {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 160ms ease;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger[aria-expanded="true"] .pxds-select-chevron {
  transform: rotate(180deg);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-menu {
  position: absolute;
  z-index: 150;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  max-height: min(360px, 45dvh);
  padding: 5px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--pxds-border-strong);
  border-radius: 9px;
  color: var(--pxds-text);
  background: var(--pxds-surface-1);
  box-shadow: var(--pxds-shadow-layer-2);
  transform-origin: top center;
  animation: pxds-select-menu-in 180ms ease-out both;
  scrollbar-color: color-mix(in srgb, var(--pxds-text-subtle) 58%, transparent) transparent;
  scrollbar-width: thin;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-menu[hidden] {
  display: none;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-group {
  position: sticky;
  top: -5px;
  z-index: 1;
  margin: 5px 3px 3px;
  padding: 8px 9px 6px;
  border-bottom: 1px solid var(--pxds-border);
  color: var(--pxds-text-muted);
  background: var(--pxds-surface-1);
  font-size: 9px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-group:first-child {
  margin-top: 0;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-option {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--pxds-text);
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-option:hover:not(:disabled),
:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-option:focus-visible {
  background: var(--pxds-surface-3);
  outline: none;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-option:focus-visible {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--pxds-brand) 64%, transparent);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-option.is-selected {
  border-color: color-mix(in srgb, var(--color-success) 56%, var(--pxds-border));
  color: var(--color-success);
  background: var(--color-success-surface);
  font-weight: 700;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-option:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-check {
  flex: 0 0 auto;
  color: var(--pxds-brand);
  font-weight: 800;
}

/* Multi-select controls use the same downward mockup popover language. */
:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu {
  position: relative;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu[open] {
  z-index: 120;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu > summary {
  min-height: 35px;
  gap: 8px;
  padding: 7px 9px;
  border-color: var(--pxds-border-strong);
  border-radius: 7px;
  color: var(--pxds-text-subtle);
  background: var(--pxds-surface-1);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

/* A closed multi-select is the same control as a normal PXDS menu. Its only
   behavioral difference is that the opened list contains checkboxes. */
.node-system-page #user-view [data-user-field-card] .d3-user-multi-menu > summary {
  box-sizing: border-box;
  width: 100%;
  min-height: 35px;
  padding: 7px 9px;
  border: 1px solid var(--pxds-border-strong) !important;
  border-radius: 7px;
  color: var(--pxds-text-subtle) !important;
  background: var(--pxds-surface-1) !important;
  box-shadow: none !important;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.node-system-page #user-view [data-user-field-card] .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary {
  border-color: transparent !important;
  color: #ffffff !important;
  background: var(--pxds-brand-fill) !important;
  font-weight: 700;
  color-scheme: dark;
}

.node-system-page #user-view [data-user-field-card] .d3-user-multi-menu > summary :is(span, i, svg) {
  color: inherit !important;
}

.node-system-page #user-view [data-user-field-card] .d3-user-multi-menu > summary > span {
  font-family: inherit !important;
  font-size: inherit !important;
  font-weight: inherit !important;
  line-height: inherit !important;
  letter-spacing: inherit !important;
}

.node-system-page #user-view [data-user-field-card] .d3-user-multi-menu > summary:hover {
  border-color: color-mix(in srgb, var(--pxds-brand) 72%, var(--pxds-border-strong)) !important;
}

html[data-theme="light"] .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu:not(:has(.d3-user-menu-option.is-selected)) > summary:hover {
  color: var(--pxds-text) !important;
  background: var(--pxds-hover-surface) !important;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu > summary:focus-visible {
  outline: 2px solid var(--pxds-brand);
  outline-offset: 2px;
}

html[data-theme="light"] :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu:not(:has(.d3-user-menu-option.is-selected)) > summary:hover {
  color: var(--pxds-text);
  background: var(--pxds-hover-surface);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary {
  border-color: transparent;
  color: #ffffff;
  background: var(--pxds-brand-fill);
  font-weight: 700;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-chevron {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  margin-inline: 4px;
  border-color: currentColor;
  transition: transform 160ms ease;
}

.node-system-page #user-view .d3-user-menu-chevron {
  width: 16px;
  height: 16px;
  margin: 0;
  border: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: none;
}

.node-system-page #user-view .d3-user-multi-menu[open] .d3-user-menu-chevron {
  transform: rotate(180deg);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-options {
  position: absolute;
  z-index: 150;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  max-height: min(360px, 45dvh);
  margin: 0;
  padding: 5px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-color: var(--pxds-border-strong);
  border-radius: 9px;
  color: var(--pxds-text);
  background: var(--pxds-surface-1);
  box-shadow: var(--pxds-shadow-layer-2);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-option {
  min-height: 38px;
  margin: 0 !important;
  padding: 9px 12px;
  border-color: transparent;
  border-radius: 6px;
  color: var(--pxds-text);
  background: transparent;
  font-size: 12px;
  font-weight: 500;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-option:hover:not(.is-limit-blocked) {
  background: var(--pxds-surface-3);
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-option.is-selected {
  border-color: color-mix(in srgb, var(--color-success) 56%, var(--pxds-border));
  color: var(--color-success) !important;
  background: var(--color-success-surface) !important;
  font-weight: 700;
}

:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-option.is-selected > span {
  color: inherit !important;
  opacity: 1;
}

html[data-theme="light"] .node-system-page #user-view .d3-user-multi-menu:not(:has(.d3-user-menu-option.is-selected)) > summary,
html[data-theme="light"] .node-system-page #user-view .d3-user-menu-options {
  background: #ffffff !important;
}

/* Validation failures may still rebuild a field. Do not replay the entrance
   animation when its prior open state is restored. Successful choices update
   in place in app.js and never rebuild the menu. */
.node-system-page #user-view .d3-user-multi-menu.is-state-restored[open] > .d3-user-menu-options {
  animation: none !important;
}

/* The shared Debug menu predates the User UI 10px readability floor. Keep the
   compact limit evidence, but do not inherit its historical 8px text size. */
:is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-limit {
  font-size: var(--pxds-type-status, 10px);
}

@keyframes pxds-select-menu-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-trigger,
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-chevron,
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-menu-chevron {
    transition: none;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .pxds-select-menu,
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu[open] > .d3-user-menu-options {
    animation: none;
  }
}

/* Every mobile multi-select expands in the document flow so its options cannot
   overlap the next User UI section. This gives People/activity choices the
   same compact behavior already used by Materials and Colors. */
@media (max-width: 700px) {
  /* Mobile multi-select fields use the same flat field rhythm as the normal
     PXDS selects. The desktop material/color cards and grids remain intact. */
  .node-system-page #user-view .d3-user-category[data-d3-user-category="materials"] .d3-user-field--grid,
  html[data-theme="light"] .node-system-page #user-view .d3-user-category[data-d3-user-category="materials"] .d3-user-field--grid {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu[open] {
    z-index: auto;
  }

  /* Match the closed normal-menu trigger exactly while retaining the native
     multi-select state behind this details control. The extra field-card
     selector intentionally wins over the older placeholder correction. */
  .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu > summary,
  .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary {
    width: 100%;
    min-height: 35px;
    padding: 7px 9px;
    border: 1px solid var(--pxds-border-strong) !important;
    border-radius: 7px;
    color: var(--pxds-text-subtle) !important;
    background: var(--pxds-surface-1) !important;
    box-shadow: none !important;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
  }

  .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu .d3-user-menu-chevron {
    margin-inline: 4px;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu > summary,
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary {
    border-color: var(--pxds-border-strong) !important;
    color: var(--pxds-text-subtle) !important;
    background: var(--pxds-surface-1) !important;
    box-shadow: none !important;
    color-scheme: normal;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu > summary :is(span, i),
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary :is(span, i) {
    color: inherit !important;
  }

  html[data-theme="light"] .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu:not(:has(.d3-user-menu-option.is-selected)) > summary {
    background: #ffffff !important;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu > .d3-user-menu-options {
    position: static;
    inset: auto;
    width: 100%;
    margin-top: 6px;
    color: var(--pxds-text);
    background: var(--pxds-surface-1);
    box-shadow: var(--pxds-shadow-layer-1);
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-option {
    min-height: 44px;
    margin: 0;
    color: var(--pxds-text);
    background: transparent;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-option > input[type="checkbox"] {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: var(--pxds-brand);
    color-scheme: normal;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-option > span,
  html[data-theme="light"] :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-option > span {
    color: inherit !important;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-option.is-selected {
    border-color: color-mix(in srgb, var(--color-success) 56%, var(--pxds-border));
    color: var(--color-success);
    background: var(--color-success-surface);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-success) 34%, transparent);
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-limit.is-at-limit,
  html[data-theme="light"] :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-user-multi-menu .d3-user-menu-limit.is-at-limit {
    border-color: var(--pxds-border-strong);
    color: var(--pxds-text-subtle);
    background: var(--pxds-surface-2);
    box-shadow: none;
  }

  /* Once at least one value is checked, use the same completed fill as a
     normal PXDS menu with a selected value. Empty multi-selects stay neutral. */
  .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary {
    border-color: transparent !important;
    color: #ffffff !important;
    background: var(--pxds-brand-fill) !important;
    box-shadow: none !important;
    font-weight: 700;
    color-scheme: dark;
  }

  .node-system-page #user-view [data-user-field-card] .d3-user-multi-menu:has(.d3-user-menu-option.is-selected) > summary :is(span, i) {
    color: #ffffff !important;
  }

}
