// ─── Wrapper ──────────────────────────────────────────────────────────────────
.agentSelectorWrapper {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid rgba(26, 23, 22, 0.06);
  border-radius: 8px;
  box-sizing: border-box;
  width: 100%;
  transition: all 0.2s ease;
  margin-bottom: 12px;
}

// ─── Collapsed (icon only) ────────────────────────────────────────────────────
.agentSelectorCollapsed {
  position: relative;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(43, 18, 0, 0.04);
  border: 1px solid rgba(26, 23, 22, 0.08);
  border-radius: 8px;
  color: #f07e26;
  cursor: default;
  margin-bottom: 12px;
  transition: all 0.2s ease;

  &:hover {
    background: rgba(43, 18, 0, 0.08);
    border-color: rgba(240, 126, 38, 0.3);
  }
}

.collapsedStatusIndicator {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: inline-flex;
}

// ─── Label ────────────────────────────────────────────────────────────────────
.agentSelectorLabel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  user-select: none;

  svg {
    opacity: 0.5;
  }
}

.agentCountBadge {
  font-size: 12px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.4);
}

.managementLink {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 500;
  color: #f07e26;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;

  &:hover {
    color: #d96c18;
  }
}

// ─── Select Component ─────────────────────────────────────────────────────────
.agentSelector {
  width: 100%;

  :global {
    .qwenpaw-select-selector {
      border: none !important;
      background: transparent !important;
      box-shadow: none !important;
      height: 32px !important;
      font-size: 13px;
      font-weight: normal;
      border-radius: 8px !important;
      transition: all 0.2s ease;
      padding: 0 !important;

      &:hover {
        border: none !important;
        background: transparent !important;
      }

      &:focus {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
      }
    }

    .ant-select-selection-item {
      padding: 0 !important;
      line-height: 22px;
    }

    .ant-select-arrow {
      color: rgba(26, 23, 22, 0.35);
      right: 8px;

      .ant-select-suffix {
        display: flex;
        align-items: center;
      }
    }

    .ant-select-focused {
      .ant-select-selector {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
      }
    }
  }
}

// ─── Selected Agent Label ─────────────────────────────────────────────────────
.selectedAgentLabel {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(0, 0, 0, 0.85);

  svg {
    flex-shrink: 0;
    color: #f07e26;
    opacity: 0.85;
  }

  span {
    font-weight: 600;
    font-size: 13px;
  }
}

// ─── Agent Badge ──────────────────────────────────────────────────────────────
// (removed - badge is now inline in label)

// ─── Dropdown Header ─────────────────────────────────────────────────────────
.dropdownHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  border-bottom: 1px solid rgba(26, 23, 22, 0.06);
  margin-bottom: 2px;
}

.dropdownHeaderTitle {
  font-size: 12px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.4);
}

// ─── Dropdown ─────────────────────────────────────────────────────────────────
.agentSelectorDropdown {
  border-radius: 12px !important;
  overflow: hidden;
  min-width: 242px !important;
  left: 15px !important;
  top: 140px !important;
  border: 1px solid rgba(26, 23, 22, 0.06) !important;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.06) !important;
  :global {
    .qwenpaw-select-item {
      padding: 0 !important;
      border-radius: 8px;
      margin: 3px 6px;
      transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);

      &:hover {
        background: rgba(43, 18, 0, 0.06) !important;
      }

      &.qwenpaw-select-item-option-selected {
        background: rgba(43, 18, 0, 0.06) !important;

        .agentOptionIcon {
          background: linear-gradient(135deg, #f07e26 0%, #f5a05a 100%);
          border-color: transparent;
          color: #ffffff;
          box-shadow: 0 2px 8px rgba(240, 126, 38, 0.4);
        }
      }
    }

    .ant-select-item {
      padding: 0 !important;
      border-radius: 8px;
      margin: 3px 6px;
      transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);

      &:hover {
        background: rgba(43, 18, 0, 0.06) !important;
      }

      &.ant-select-item-option-selected {
        background: rgba(43, 18, 0, 0.06) !important;

        .agentOptionIcon {
          background: linear-gradient(135deg, #f07e26 0%, #f5a05a 100%);
          border-color: transparent;
          color: #ffffff;
          box-shadow: 0 2px 8px rgba(240, 126, 38, 0.4);
        }
      }
    }

    .rc-virtual-list {
      padding: 4px 0;
    }

    .ant-select-item-group,
    .qwenpaw-select-item-group {
      min-height: 24px;
      padding: 5px 14px 2px !important;
      color: rgba(26, 26, 46, 0.42) !important;
      font-size: 10px;
      font-weight: 650;
      letter-spacing: 0.06em;
      line-height: 1.4;
      text-transform: uppercase;
    }
  }
}

.dropdownContent {
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.enabledAgentList {
  min-height: 0;
}

// ─── Agent Option ─────────────────────────────────────────────────────────────
.agentOption {
  position: relative;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-radius: 8px;
  outline: none;
  transform-origin: center;
  transition:
    background 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);

  &:focus-visible {
    background: rgba(240, 126, 38, 0.06);
    box-shadow: inset 0 0 0 1px rgba(240, 126, 38, 0.32);
  }
}

.agentOptionDisabled {
  opacity: 0.68;
}

.agentOptionPressing {
  z-index: 1;
  background: rgba(240, 126, 38, 0.055);
  box-shadow: 0 7px 18px rgba(72, 42, 20, 0.12);
  animation: pinHoldWiggle 0.14s ease-in-out infinite alternate;
}

.agentOptionPinFeedback {
  animation: pinWiggle 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

.agentOptionHeader {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agentStatusColumn {
  width: 12px;
  flex: 0 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.agentToggleButton {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: rgba(26, 26, 46, 0.48);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  transition:
    color 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;

  &:hover:not(:disabled),
  &:focus-visible:not(:disabled) {
    color: #f07e26;
    background: rgba(240, 126, 38, 0.08);
    border-color: rgba(240, 126, 38, 0.18);
    outline: none;
  }

  &:disabled {
    cursor: not-allowed;
    opacity: 0.35;
  }
}

.toggleSpinner {
  animation: toggleSpin 0.9s linear infinite;
}

@keyframes toggleSpin {
  to {
    transform: rotate(360deg);
  }
}

.disabledAgentSection {
  border-top: 1px solid rgba(26, 23, 22, 0.08);
  padding: 4px 6px 6px;
}

.disabledAgentHeader {
  width: 100%;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  color: rgba(26, 26, 46, 0.58);
  background: transparent;
  border: none;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;

  &:hover,
  &:focus-visible {
    color: rgba(26, 26, 46, 0.82);
    background: rgba(43, 18, 0, 0.04);
    outline: none;
  }

  svg {
    transition: transform 0.18s ease;
  }
}

.disabledChevronExpanded {
  transform: rotate(180deg);
}

.disabledAgentList {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 2px;
}

.disabledAgentRow {
  border-radius: 8px;

  &:hover,
  &:focus-within {
    background: rgba(43, 18, 0, 0.04);
  }
}

.agentOptionIcon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #fff8f2 0%, #fff0e5 100%);
  border: 1px solid rgba(240, 126, 38, 0.15);
  border-radius: 8px;
  color: #f07e26;
  transition: all 0.2s ease;

  .agentOption:hover & {
    background: linear-gradient(135deg, #ffe9d4 0%, #fff0e5 100%);
    border-color: rgba(240, 126, 38, 0.3);
    color: #f07e26;
    box-shadow: 0 2px 6px rgba(240, 126, 38, 0.15);
  }
}

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

.agentOptionName {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1a1a2e;
  line-height: 1.4;

  .agentOptionNameText {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.pinnedIndicator {
  flex: 0 0 auto;
  color: #f07e26;
  filter: drop-shadow(0 1px 2px rgba(240, 126, 38, 0.18));
}

.activeIndicator {
  flex-shrink: 0;
  color: #f07e26;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.agentOptionDescription {
  font-size: 11px;
  color: #8c8c8c;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agentOptionId {
  font-size: 10px;
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  color: rgba(240, 126, 38, 0.45);
  letter-spacing: 0.3px;
  margin-left: 52px;
  padding-top: 3px;
  border-top: 1px solid rgba(240, 126, 38, 0.08);
}

@keyframes pinHoldWiggle {
  from {
    transform: translateY(-2px) rotate(-0.45deg) scale(1.012);
  }
  to {
    transform: translateY(-2px) rotate(0.45deg) scale(1.012);
  }
}

@keyframes pinWiggle {
  0%,
  100% {
    transform: rotate(0deg) scale(1);
  }
  20% {
    transform: rotate(-1.3deg) scale(1.012);
  }
  40% {
    transform: rotate(1.1deg) scale(1.012);
  }
  60% {
    transform: rotate(-0.8deg) scale(1.006);
  }
  80% {
    transform: rotate(0.5deg) scale(1.003);
  }
}

@media (prefers-reduced-motion: reduce) {
  .agentOption,
  .pinnedIndicator {
    transition: none;
  }

  .agentOptionPressing,
  .agentOptionPinFeedback {
    animation: none;
    transform: none;
  }
}

// ─── Dark mode overrides ───────────────────────────────────────────────────────
:global(.dark-mode) {
  .agentSelectorWrapper {
    background: #1e1e1e;
    border-color: rgba(255, 255, 255, 0.08);
  }

  .agentSelectorCollapsed {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
    color: #f07e26;

    &:hover {
      background: rgba(255, 255, 255, 0.08);
      border-color: rgba(240, 126, 38, 0.4);
    }
  }

  .agentSelectorLabel {
    color: rgba(255, 255, 255, 0.55);

    svg {
      opacity: 0.7;
    }
  }

  .agentCountBadge {
    color: rgba(255, 255, 255, 0.45);
  }

  .dropdownHeader {
    border-bottom-color: rgba(255, 255, 255, 0.08);
  }

  .dropdownHeaderTitle {
    color: rgba(255, 255, 255, 0.4);
  }

  .agentSelectorDropdown {
    :global {
      .ant-select-item-group,
      .qwenpaw-select-item-group {
        color: rgba(255, 255, 255, 0.4) !important;
      }
    }
  }

  .agentSelector {
    :global {
      .ant-select-selector {
        border: none !important;
        background: transparent !important;

        &:hover {
          border: none !important;
          background: transparent !important;
        }

        &:focus {
          border: none !important;
          background: transparent !important;
          box-shadow: none !important;
        }
      }

      .ant-select-arrow {
        color: rgba(255, 255, 255, 0.45);
      }

      .ant-select-focused .ant-select-selector {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
      }
    }
  }

  .selectedAgentLabel {
    color: rgba(255, 255, 255, 0.9);

    svg {
      color: #f5a05a;
      opacity: 0.9;
    }
  }

  .managementLink {
    color: #f5a05a;

    &:hover {
      color: #f07e26;
    }
  }

  .agentSelectorDropdown {
    border-color: rgba(255, 255, 255, 0.08) !important;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.4),
      0 2px 8px rgba(0, 0, 0, 0.2) !important;

    :global {
      .ant-select-item {
        &:hover {
          background: rgba(255, 255, 255, 0.08) !important;
        }

        &.ant-select-item-option-selected {
          background: rgba(255, 255, 255, 0.08) !important;

          .agentOptionIcon {
            background: linear-gradient(135deg, #f07e26 0%, #f5a05a 100%);
            border-color: transparent;
            color: #ffffff;
            box-shadow: 0 2px 8px rgba(240, 126, 38, 0.5);
          }
        }
      }
    }
  }

  .agentOptionIcon {
    background: linear-gradient(
      135deg,
      rgba(240, 126, 38, 0.15) 0%,
      rgba(240, 126, 38, 0.08) 100%
    );
    border-color: rgba(245, 160, 90, 0.2);
    color: #f5a05a;

    .agentOption:hover & {
      background: linear-gradient(
        135deg,
        rgba(240, 126, 38, 0.3) 0%,
        rgba(240, 126, 38, 0.15) 100%
      );
      border-color: rgba(245, 160, 90, 0.4);
      color: #f5b87a;
      box-shadow: 0 2px 8px rgba(240, 126, 38, 0.3);
    }
  }

  .agentOptionName {
    color: rgba(255, 255, 255, 0.88);
  }

  .agentOption:focus-visible,
  .agentOptionPressing {
    background: rgba(240, 126, 38, 0.12);
  }

  .agentOptionDescription {
    color: rgba(255, 255, 255, 0.4);
  }

  .agentOptionId {
    color: rgba(245, 160, 90, 0.5);
    border-top-color: rgba(245, 160, 90, 0.12);
  }

  .agentToggleButton {
    color: rgba(255, 255, 255, 0.48);

    &:hover:not(:disabled),
    &:focus-visible:not(:disabled) {
      color: #f5a05a;
      background: rgba(240, 126, 38, 0.14);
      border-color: rgba(245, 160, 90, 0.22);
    }
  }

  .disabledAgentSection {
    border-top-color: rgba(255, 255, 255, 0.08);
  }

  .disabledAgentHeader {
    color: rgba(255, 255, 255, 0.5);

    &:hover,
    &:focus-visible {
      color: rgba(255, 255, 255, 0.82);
      background: rgba(255, 255, 255, 0.05);
    }
  }

  .disabledAgentRow {
    &:hover,
    &:focus-within {
      background: rgba(255, 255, 255, 0.05);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .toggleSpinner {
    animation-duration: 1.8s;
  }

  .disabledAgentHeader svg {
    transition: none;
  }
}
