/* ══════════════════════════════════════════════════════════════════════
   ADS Select — shared combobox/listbox component
   ──────────────────────────────────────────────────────────────────────
   One implementation for every ADS Select in V2. `v2-select.js` upgrades
   a native <select data-ads-select> into this markup, so any view that
   needs a dropdown gets the same chrome, states, and keyboard model.

   Chrome follows the in-project ADS spec in assets/ads-theme.css
   (.dropdown-menu surface + .menu-item rows) and the Ads Design System
   "Select" / "Select Option" components, whose Selected state carries a
   Check icon rather than colour alone.

   Geometry is deliberately token-driven: hosts set the vars below to
   match their own Figma frame instead of forking the component.
   ══════════════════════════════════════════════════════════════════════ */

.ads-select {
  --ads-select-height: 32px;
  --ads-select-pad-x: 12px;
  --ads-select-radius: var(--radius-field, 8px);
  --ads-select-font-size: 14px;
  --ads-select-line: 20px;
  --ads-select-border: rgba(15, 18, 20, 0.2);
  --ads-select-border-hover: rgba(15, 18, 20, 0.4);
  --ads-select-brand: var(--ads-brand, #4045c2);
  --ads-select-text: var(--ads-gray-600, #1e2528);
  --ads-select-surface: var(--ads-card-bg, #ffffff);

  position: relative;
}

/* The native control stays in the DOM as the single source of period
   state — it keeps its value and still emits `change` — but it must not
   render, or the OS menu would remain reachable underneath. */
.ads-select-native {
  display: none !important;
}

/* ── Trigger (closed state) ────────────────────────────────────────── */
.ads-select-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: var(--ads-select-height);
  margin: 0;
  padding: 0 var(--ads-select-pad-x);
  box-sizing: border-box;
  background: var(--ads-select-surface);
  border: 1px solid var(--ads-select-border);
  border-radius: var(--ads-select-radius);
  font-family: inherit;
  font-size: var(--ads-select-font-size);
  line-height: var(--ads-select-line);
  color: var(--ads-select-text);
  text-align: left;
  cursor: pointer;
}

.ads-select-value {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ads-select-chevron {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.ads-select-chevron svg {
  display: block;
  width: 16px;
  height: 16px;
}

.ads-select-trigger:hover {
  border-color: var(--ads-select-border-hover);
}

.ads-select-trigger:focus {
  outline: none;
}

.ads-select-trigger:focus-visible {
  outline: 2px solid var(--ads-select-brand);
  outline-offset: 1px;
  border-color: var(--ads-select-brand);
}

/* Open reuses the focus treatment so the trigger still reads as active
   while the pointer is down in the menu and focus-visible is absent. */
.ads-select-trigger[aria-expanded="true"] {
  border-color: var(--ads-select-brand);
}

.ads-select-trigger[aria-invalid="true"] {
  border-color: var(--ads-red-100, #db5461);
}

.ads-select-trigger[aria-expanded="true"] .ads-select-chevron {
  transform: rotate(180deg);
}

.ads-select-trigger:disabled {
  background: #f4f6f7;
  color: #9eb0bd;
  cursor: not-allowed;
}

/* ── Menu (open state) ─────────────────────────────────────────────── */
/* Absolutely positioned so opening never reflows the tabs or table. */
.ads-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  z-index: 400;
  margin: 0;
  padding: 4px 0;
  box-sizing: border-box;
  list-style: none;
  /* Fallbacks are required: a portaled menu leaves .ads-select, so the
     host custom properties are no longer in scope. */
  background: var(--ads-select-surface, var(--ads-card-bg, #ffffff));
  border: 1px solid var(--ads-select-border, rgba(15, 18, 20, 0.2));
  border-radius: var(--ads-select-radius, var(--radius-field, 8px));
  box-shadow: 0 4px 12px rgba(15, 18, 20, 0.3);
  color: var(--ads-select-text, var(--ads-gray-600, #1e2528));
  font-size: var(--ads-select-font-size, 14px);
  line-height: var(--ads-select-line, 20px);
  max-height: 280px;
  overflow-y: auto;
}

/* Popover layer. Open menus are moved to document.body so a modal
   scroller cannot clip them; this z-index sits above .edl-modal-overlay
   (1000) and is owned by the select, not by the host page. */
.ads-select-menu.ads-select-menu--portal {
  position: fixed;
  z-index: 1200;
  top: auto;
}

.ads-select-menu[hidden] {
  display: none;
}

/* ── Option rows ───────────────────────────────────────────────────── */
.ads-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 8px 12px;
  box-sizing: border-box;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: var(--ads-select-font-size);
  line-height: var(--ads-select-line);
  color: var(--ads-select-text);
  text-align: left;
  cursor: pointer;
}

.ads-select-option-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: normal;
}

.ads-select-option:hover:not(:disabled) {
  background: rgba(15, 18, 20, 0.05);
}

.ads-select-option:disabled,
.ads-select-option[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Keyboard cursor. Focus stays on the trigger and the active row is named
   by aria-activedescendant, so it needs its own visible marker — shown only
   while navigating by key, since pointer users already get hover. */
.ads-select--kb .ads-select-option.is-active {
  background: rgba(15, 18, 20, 0.05);
  outline: 2px solid var(--ads-select-brand);
  outline-offset: -2px;
}

.ads-select-option[aria-selected="true"] {
  background: var(--ads-indigo-50, #e2e3f2);
  color: var(--ads-select-brand);
  font-weight: 600;
}

/* Check glyph — the Selected indicator carried by the ADS Select Option
   component. Reserved at all times so rows don't shift on selection. */
.ads-select-check {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  visibility: hidden;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'><path fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 7.5l3.2 3.2L12 4'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'><path fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M2 7.5l3.2 3.2L12 4'/></svg>") center / contain no-repeat;
}

.ads-select-option[aria-selected="true"] .ads-select-check {
  visibility: visible;
}
