/* ==========================================================================
   Component: Select Dropdown System
   New trigger + content variants that compose with the locked Pattern 16
   (Hero Pill + Rich Description) to form the canonical Select Dropdown
   family. See /a/design-system/patterns/pattern-23-select-dropdown-system.

   Triggers (any of these can open any of the dropdown content variants):
     .hps-trigger          — Hero Pill (LOCKED, defined in hero-pill-select.css)
     .ee-picker__trigger   — Picker Pill (existing, defined in experience_editor/)
     .sd-trigger           — Traditional Select (NEW, defined here)

   Dropdown content:
     .hps-rich-drop        — Rich Description (LOCKED, defined in hero-pill-select.css)
     .sd-simple-drop       — Simple Description (NEW, defined here)
     .sd-search-drop       — Search-Tree (NEW, defined here)
   ========================================================================== */


/* ─── Wrapper (.sd-control) ────────────────────────────────────────────────
   Provides positioning context for absolute-positioned dropdowns and
   constrains both the trigger and the dropdown to the same width. Optional
   --compact modifier caps width at --field-max-width-compact at 640px+
   (mirrors .form-input--compact / .form-select--compact behavior).
   ========================================================================== */

.sd-control {
  position: relative;
  width: 100%;
}

@media (min-width: 640px) {
  .sd-control--compact {
    max-width: var(--field-max-width-compact);
  }
}


/* ─── Traditional Select trigger (.sd-trigger) ─────────────────────────────
   Polished promotion of the legacy .mp-trigger (pages/participation/step.css).
   Rectangular full-width button shaped like a polished native select, with
   an optional leading slot that consumers populate with an icon, an avatar,
   or nothing.

   Anatomy:
     .sd-trigger
       .sd-trigger__lead          (optional leading slot)
         .sd-trigger__lead--avatar  (28px circle for person pickers)
         .sd-trigger__lead--icon    (18px material symbol)
       .sd-trigger__value         (current value, semibold)
         .sd-trigger__value--placeholder (regular weight, tertiary text)
       .sd-trigger__caret         (trailing chevron)
   ========================================================================== */

.sd-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.sd-trigger:hover { border-color: var(--accent-primary); }

.sd-trigger[aria-expanded="true"] {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
  outline: none;
}

.sd-trigger__lead {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-tertiary);
}
.sd-trigger__lead .material-symbols-rounded { font-size: 18px; }

.sd-trigger__lead--avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  overflow: hidden;
}
.sd-trigger__lead--avatar .material-symbols-rounded { font-size: 16px; }
.sd-trigger__lead--avatar img { width: 100%; height: 100%; object-fit: cover; }

.sd-trigger__value {
  flex: 1;
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sd-trigger__value--placeholder {
  color: var(--input-placeholder);
  font-weight: var(--weight-regular);
}

.sd-trigger__caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.sd-trigger__caret .material-symbols-rounded { font-size: 18px; }


/* ─── Simple Description content (.sd-simple-*) ────────────────────────────
   Denser sibling of .hps-rich-drop. Icon + name only — no description.
   Use when option labels are self-explanatory or vertical space is tight.

   Anatomy:
     .sd-simple-drop
       .sd-simple-opt
         .sd-simple-opt__icon
         .sd-simple-opt__name
       .sd-simple-opt--current   (selected row tint)
   ========================================================================== */

.sd-simple-drop {
  margin: 0;
  padding: var(--space-1);
  background: var(--surface-overlay);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sd-simple-opt {
  /* position: relative is REQUIRED — anchors the visually-hidden
     <input> child (see below). See DS Conventions →
     "Visually-hidden form inputs" at /a/design-system/contribute. */
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1-5) var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  width: 100%;
}
.sd-simple-opt:hover { background: var(--surface-hover); }
.sd-simple-opt--current,
.sd-simple-opt:has(input:checked) { background: var(--accent-subtle); }
.sd-simple-opt:has(input:checked) .sd-simple-opt__icon { color: var(--accent-primary); }
.sd-simple-opt:has(input:checked) .sd-simple-opt__name { color: var(--accent-primary); }

/* Visually-hide form inputs inside sd-* option rows. Selection state is
   expressed by the row tint (via :has(input:checked)). */
.sd-simple-opt > input[type="radio"],
.sd-simple-opt > input[type="checkbox"],
.sd-tree-option > input[type="radio"],
.sd-tree-option > input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.sd-simple-opt__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  color: var(--text-tertiary);
}
.sd-simple-opt__icon .material-symbols-rounded { font-size: 14px; }
.sd-simple-opt--current .sd-simple-opt__icon { color: var(--accent-primary); }

.sd-simple-opt__name {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  line-height: 1.3;
}
.sd-simple-opt--current .sd-simple-opt__name { color: var(--accent-primary); }


/* ─── Search-Tree content (.sd-search-*) ───────────────────────────────────
   Search input at top + scrollable hierarchical list below. Org-header rows
   are non-selectable and indented by depth; child rows nest one level deeper.
   Tree-aware filtering wired via search_select_controller's data-org-id /
   data-parent-id contract (matching reveals ancestors + descendants).

   Anatomy:
     .sd-search-drop
       .sd-search-field           (search input, full-width)
       .sd-search-list            (scroll container, max-height)
         .sd-tree-header          (non-selectable org row)
           .material-symbols-rounded
           .sd-tree-header__name
         .sd-tree-option          (selectable child row, label-wrapped)
           .sd-tree-option__radio (visually hidden form input)
           .sd-tree-option__avatar (optional 24px circle)
           .sd-tree-option__name
         .sd-tree-option--current (selected row tint)
         .sd-tree-empty           (zero-state row when filtered list is empty)
   ========================================================================== */

.sd-search-drop {
  margin: 0;
  padding: var(--space-2);
  background: var(--surface-overlay);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sd-search-field {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
}
.sd-search-field::placeholder { color: var(--input-placeholder); }
.sd-search-field:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.sd-search-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 320px;
  overflow-y: auto;
}

/* Tree depth indent — consumers set inline `style="--sd-tree-depth: N"` per
   row. Each level adds --space-4 of left padding on top of the base. */
.sd-tree-header,
.sd-tree-option {
  --sd-tree-depth: 0;
}

.sd-tree-header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1-5) var(--space-2);
  padding-left: calc(var(--space-2) + (var(--space-4) * var(--sd-tree-depth)));
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: var(--radius-sm);
  user-select: none;
  cursor: default;
}
.sd-tree-header .material-symbols-rounded {
  font-size: 14px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.sd-tree-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  padding-left: calc(var(--space-2) + (var(--space-4) * var(--sd-tree-depth)));
  border-radius: var(--radius-sm);
  cursor: pointer;
  /* position: relative is REQUIRED — anchors the visually-hidden
     .sd-tree-option__radio child. See DS Conventions →
     "Visually-hidden form inputs" at /a/design-system/contribute. */
  position: relative;
}
.sd-tree-option:hover,
.sd-tree-option[aria-selected="true"] { background: var(--surface-hover); }
.sd-tree-option--current,
.sd-tree-option:has(input:checked) { background: var(--accent-subtle); }

/* Consumer-driven hide: callers set `data-org-hidden` to filter rows out
   of view without disturbing search-select's _showAll() reset. Mirrors the
   existing rule on .ee-picker__option in pages/admin/participation-hub.css
   so both class sets honor the same data-attribute contract. */
.sd-tree-option[data-org-hidden],
.sd-tree-header[data-org-hidden] {
  display: none;
}

.sd-tree-option__radio {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

.sd-tree-option__avatar {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--surface-sunken);
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
  overflow: hidden;
}
.sd-tree-option__avatar img { width: 100%; height: 100%; object-fit: cover; }

.sd-tree-option__name {
  font-size: var(--text-sm);
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sd-tree-option--current .sd-tree-option__name {
  color: var(--accent-primary);
  font-weight: var(--weight-semibold);
}

.sd-tree-empty {
  padding: var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}
