/* Custom Dropdown */
.custom-select {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  user-select: none;
}

.custom-select-trigger {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  background: var(--color-surface);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
  transition: border-color 0.2s ease;
  min-height: 44px;
  box-sizing: border-box;
  user-select: none;
}

.custom-select-trigger-text {
  user-select: none;
}

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

.custom-select-trigger.placeholder {
  color: var(--color-text-muted);
}

.custom-select-trigger.open {
  border-color: var(--color-accent);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* Flipped trigger (dropdown appears above) */
.custom-select-trigger.open.flipped {
  border-bottom-left-radius: var(--radius-small);
  border-bottom-right-radius: var(--radius-small);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.custom-select-arrow {
  margin-left: 8px;
  transition: transform 0.2s ease;
  color: var(--color-text-muted);
}

.custom-select-trigger.open .custom-select-arrow {
  transform: rotate(180deg);
}

.custom-select.disabled .custom-select-trigger {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

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

.custom-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 350px;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-accent);
  border-top: none;
  border-bottom-left-radius: var(--radius-small);
  border-bottom-right-radius: var(--radius-small);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
  z-index: 100;
  display: none;
}

.custom-select-dropdown.open {
  display: block;
}

/* Fields in scrolling dialogs and popovers (custom-select-field.js `fixedMenu`):
   the menu is placed against the viewport, and CustomSelect anchors it to its
   trigger on open, so the dialog's scroll box does not clip it. */
.custom-select.custom-select-fixed-menu > .custom-select-dropdown {
  position: fixed;
  top: auto;
  left: auto;
  right: auto;
  z-index: 10001;
}

/* Flipped dropdown (appears above trigger) */
.custom-select-dropdown.flipped {
  border-top: 1px solid var(--color-accent);
  border-bottom: none;
  border-radius: var(--radius-small) var(--radius-small) 0 0;
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.15);
}

.custom-select-option {
  padding: 12px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s ease;
  user-select: none;
}

.custom-select-option:hover,
.custom-select-option.active {
  background: rgba(63, 114, 255, 0.08);
}

.custom-select-option.selected.active {
  background: rgba(63, 114, 255, 0.2);
}

.custom-select-option.selected {
  background: rgba(63, 114, 255, 0.12);
  font-weight: 600;
  color: var(--color-accent);
}

.custom-select-option.disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
  font-style: italic;
}

.custom-select-option.disabled.hidden-placeholder {
  display: none;
}

.custom-select-option.disabled:hover {
  background: transparent;
}

.custom-select-option.custom-select-free-text-hint {
  font-style: italic;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

/* Non-selectable section heading row (a disabled option flagged by the caller). */
.custom-select-option.disabled.custom-select-option-heading {
  font-style: normal;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  cursor: default;
  padding-top: 10px;
  padding-bottom: 4px;
  border-top: 1px solid var(--color-border);
}

.custom-select-option.custom-select-free-text-hint:hover {
  color: var(--color-text);
  background: rgba(63, 114, 255, 0.08);
}

.custom-select-group-label {
  padding: 10px 12px 5px;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.2;
  text-transform: uppercase;
  user-select: none;
}

.custom-select-group-label:first-child {
  border-top: 0;
}

.custom-select-option-label {
  font-size: 14px;
  font-weight: 500;
}

.custom-select-option-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

/* Custom Select Search */
.custom-select-search {
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.custom-select-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  font-size: 14px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color 0.2s ease;
}

.custom-select-search-input:focus {
  border-color: var(--color-accent);
}

.custom-select-search-input::placeholder {
  color: var(--color-text-muted);
  opacity: 0.7;
}

.custom-select-options {
  max-height: 250px;
  overflow-y: auto;
}

/* ============================================
   Rich Environment Option Styles
   ============================================ */

/* Dropdown option card */
.custom-select-option.env-rich-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
}

.env-option-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

.env-option-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.env-option-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--color-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.env-option-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.env-option-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.env-meta-icon {
  vertical-align: -1px;
  opacity: 0.7;
  flex-shrink: 0;
}

.env-meta-sep {
  display: inline-block;
  width: 12px;
}

/* Trigger avatar (compact inline) */
.env-trigger-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  vertical-align: middle;
  margin-right: 8px;
  flex-shrink: 0;
}

.env-trigger-name {
  vertical-align: middle;
}

/* Failed latest image build (the environment's last_build). The dot sits on
   the avatar's corner; the trigger spells it out beside the name. */
.env-option-avatar,
.env-trigger-avatar {
  position: relative;
}

.env-build-alert-dot {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-danger);
  box-shadow: 0 0 0 2px var(--color-surface);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  line-height: 14px;
  letter-spacing: 0;
  text-align: center;
}

.env-build-alert-dot::before {
  content: '!';
}

.env-option-build-alert {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--color-danger-text);
  font-weight: 600;
}

/* Draft environment (status: draft): hidden from everyone but its managers.
   Outlined rather than filled, so it reads as "not published yet" and never
   competes with the failed-build alert. A disabled environment (status:
   disabled) is out of service: the same pill with a solid outline and muted
   text. */
.env-draft-badge,
.env-disabled-badge {
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border: 1px dashed var(--color-text-muted);
  border-radius: 999px;
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  white-space: nowrap;
  vertical-align: middle;
  flex-shrink: 0;
}

.env-disabled-badge {
  border-style: solid;
  color: var(--color-text-muted);
}

.env-option-draft,
.env-option-disabled {
  margin-left: 8px;
}

.env-trigger-draft,
.env-trigger-disabled {
  margin-left: 10px;
}

.env-trigger-build-alert {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(229, 83, 104, 0.12);
  color: var(--color-danger-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  vertical-align: middle;
  white-space: nowrap;
}

