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

: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-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-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;
}

: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;
  border-color: currentColor;
  transition: transform 160ms ease;
}

: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);
  max-height: min(360px, 45dvh);
  margin: 0;
  padding: 5px;
  overflow-y: auto;
  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;
  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);
  background: var(--color-success-surface);
  font-weight: 700;
}

/* 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;
  }
}

/* Mobile Materials and Colors menus expand in the document flow so their
   options cannot overlap the next User UI section. Selected values stay
   visible through the summary text and option outline; the closed control
   remains visually consistent with the other neutral mobile menus. */
@media (max-width: 700px) {
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-menu[open] {
    z-index: auto;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-menu > summary,
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-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-grid-mobile-menu > summary :is(span, i),
  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-menu:has(.d3-user-menu-option.is-selected) > summary :is(span, i) {
    color: inherit !important;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-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-grid-mobile-menu .d3-user-menu-option {
    color: var(--pxds-text);
    background: var(--pxds-surface-1);
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-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-grid-mobile-menu .d3-user-menu-option > span {
    color: inherit !important;
  }

  :is(.node-system-page :is(#user-view, #debug-view, #library-view), .pxds-menu-scope) .d3-grid-mobile-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-grid-mobile-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-grid-mobile-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;
  }
}
