// 下拉列表组件样式
.dropdown-container {
  position: relative;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  // 禁用状态
  &.disabled {
    opacity: 0.6;
    pointer-events: none;
  }

  // 错误状态
  &.error {
    .dropdown-wrapper {
      border-color: #FF3B30;
      box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.1);
    }
  }
}

// 背景遮罩
.dropdown-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(2px);
  opacity: 0;
  animation: fadeIn 0.2s ease forwards;
}

@keyframes fadeIn {
  to {
    opacity: 1;
  }
}

// 响应式设计
@media (max-width: 768px) {
  .dropdown-container {
    .dropdown-panel {
      left: -8px;
      right: -8px;
      max-height: 60vh;
    }

    .dropdown-search {
      padding: 16px;
    }

    .dropdown-option {
      padding: 16px;
      min-height: 56px;
    }
  }
}

// 高对比度模式支持
@media (prefers-contrast: high) {
  .dropdown-container {
    .dropdown-wrapper {
      border-width: 3px;
    }

    .dropdown-panel {
      border-width: 2px;
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    }

    .dropdown-option {
      &:hover:not(.disabled):not(.group-header) {
        background: rgba(0, 122, 255, 0.2);
      }

      &.selected:not(.group-header) {
        background: rgba(0, 122, 255, 0.3);
      }
    }
  }
}

// 减少动画模式支持
@media (prefers-reduced-motion: reduce) {
  .dropdown-container {
    * {
      transition: none !important;
      animation: none !important;
    }
  }
}

// 屏幕阅读器专用类
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

// 标签样式
.dropdown-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #1D1D1F;
  margin-bottom: 8px;
  line-height: 1.4;

  &.required {
    .required-asterisk {
      color: #FF3B30;
      margin-left: 4px;
    }
  }
}

// 下拉框包装器
.dropdown-wrapper {
  position: relative;
  background: #FFFFFF;
  border: 2px solid #E5E5E7;
  border-radius: 12px;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  cursor: pointer;
  min-height: 48px;
  
  // 悬停状态
  &:hover:not(.disabled) {
    border-color: #007AFF;
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.1);
  }

  // 聚焦状态
  &.focused {
    border-color: #007AFF;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
  }

  // 打开状态
  &.open {
    border-color: #007AFF;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
  }

  // 有值状态
  &.has-value {
    .selected-text {
      color: #1D1D1F;
    }
  }
}

// 选中值显示区域
.dropdown-display {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  min-height: 24px;
  gap: 8px;

  .selected-icon {
    font-size: 20px;
    color: #8E8E93;
    flex-shrink: 0;
  }

  .selected-text {
    flex: 1;
    font-size: 16px;
    line-height: 1.5;
    color: #1D1D1F;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    &.placeholder {
      color: #8E8E93;
    }
  }

  .clear-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: none;
    background: #F2F2F7;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;

    &:hover {
      background: #E5E5EA;
      transform: scale(1.1);
    }

    mat-icon {
      font-size: 16px;
      color: #8E8E93;
    }
  }

  .dropdown-arrow {
    font-size: 24px;
    color: #8E8E93;
    transition: transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    flex-shrink: 0;

    &.rotated {
      transform: rotate(180deg);
    }
  }
}

// 下拉面板
.dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 122, 255, 0.2);
  border-radius: 12px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  overflow: hidden;
  max-height: 320px;
  
  // 确保在深色背景下也能清晰显示
  @media (prefers-color-scheme: dark) {
    background: rgba(28, 28, 30, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 
      0 8px 32px rgba(0, 0, 0, 0.3),
      0 2px 8px rgba(0, 0, 0, 0.2),
      inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
}

// 搜索容器
.dropdown-search {
  position: relative;
  padding: 12px;
  border-bottom: 1px solid rgba(242, 242, 247, 0.6);
  background: rgba(251, 251, 253, 0.8);

  .search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: #8E8E93;
    pointer-events: none;
  }

  .search-input {
    width: 100%;
    padding: 10px 16px 10px 44px;
    border: 1px solid rgba(229, 229, 231, 0.8);
    border-radius: 8px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.9);
    outline: none;
    transition: all 0.2s ease;

    &:focus {
      border-color: #007AFF;
      background: #FFFFFF;
      box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
    }

    &::placeholder {
      color: #8E8E93;
    }
  }

  .search-clear {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: none;
    background: rgba(142, 142, 147, 0.2);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;

    &:hover {
      background: rgba(142, 142, 147, 0.3);
      transform: translateY(-50%) scale(1.1);
    }

    mat-icon {
      font-size: 14px;
      color: #8E8E93;
    }
  }

  // 深色模式适配
  @media (prefers-color-scheme: dark) {
    background: rgba(44, 44, 46, 0.8);
    border-bottom-color: rgba(255, 255, 255, 0.1);

    .search-input {
      background: rgba(58, 58, 60, 0.9);
      border-color: rgba(255, 255, 255, 0.1);
      color: #FFFFFF;

      &:focus {
        background: rgba(58, 58, 60, 1);
        border-color: #007AFF;
      }

      &::placeholder {
        color: rgba(235, 235, 245, 0.6);
      }
    }
  }
}

// 选项列表
.options-list {
  overflow-y: auto;
  
  // 自定义滚动条
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background: #C7C7CC;
    border-radius: 3px;
    
    &:hover {
      background: #AEAEB2;
    }
  }
}

// 无选项提示
.no-options {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  color: #8E8E93;
  text-align: center;

  mat-icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.6;
  }

  span {
    font-size: 14px;
  }
}

// 下拉选项
.dropdown-option {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.15s ease;
  border-bottom: 1px solid rgba(242, 242, 247, 0.5);
  gap: 12px;
  min-height: 48px;

  &:last-child {
    border-bottom: none;
  }

  // 悬停状态
  &:hover:not(.disabled):not(.group-header) {
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.08) 0%, rgba(0, 122, 255, 0.04) 100%);
    transform: translateX(2px);
  }

  // 选中状态
  &.selected:not(.group-header) {
    background: linear-gradient(135deg, rgba(0, 122, 255, 0.12) 0%, rgba(0, 122, 255, 0.06) 100%);
    color: #007AFF;
    font-weight: 600;

    .option-icon {
      color: #007AFF;
    }
  }

  // 禁用状态
  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }

  // 分组标题
  &.group-header {
    background: #F8F9FA;
    cursor: default;
    font-weight: 600;
    color: #6C757D;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 16px;
    border-bottom: 1px solid #E9ECEF;

    .group-header {
      width: 100%;
    }
  }

  .option-icon {
    font-size: 20px;
    color: #8E8E93;
    flex-shrink: 0;
    transition: color 0.15s ease;
  }

  .option-label {
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .check-icon {
    font-size: 20px;
    color: #34C759;
    flex-shrink: 0;
  }
}

// 错误信息
.error-message {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: #FF3B30;
  font-size: 13px;
  line-height: 1.4;

  mat-icon {
    font-size: 16px;
  }
}

// 帮助文本
.help-text {
  margin-top: 6px;
  color: #8E8E93;
  font-size: 13px;
  line-height: 1.4;
}

// 尺寸变体
.dropdown-container {
  // 小尺寸
  &.size-small {
    .dropdown-wrapper {
      min-height: 36px;
    }

    .dropdown-display {
      padding: 8px 12px;
      
      .selected-text {
        font-size: 14px;
      }
    }

    .dropdown-option {
      padding: 8px 12px;
      min-height: 36px;
      
      .option-label {
        font-size: 14px;
      }
    }
  }

  // 大尺寸
  &.size-large {
    .dropdown-wrapper {
      min-height: 56px;
    }

    .dropdown-display {
      padding: 16px 20px;
      
      .selected-text {
        font-size: 18px;
      }
    }

    .dropdown-option {
      padding: 16px 20px;
      min-height: 56px;
      
      .option-label {
        font-size: 16px;
      }
    }
  }
}

// 样式变体
.dropdown-container {
  // 填充样式
  &.variant-filled {
    .dropdown-wrapper {
      background: #F2F2F7;
      border: 2px solid transparent;

      &:hover:not(.disabled) {
        background: #E5E5EA;
        border-color: #007AFF;
      }

      &.focused,
      &.open {
        background: #FFFFFF;
        border-color: #007AFF;
      }
    }
  }

  // 标准样式
  &.variant-standard {
    .dropdown-wrapper {
      background: transparent;
      border: none;
      border-bottom: 2px solid #E5E5E7;
      border-radius: 0;

      &:hover:not(.disabled) {
        border-bottom-color: #007AFF;
      }

      &.focused,
      &.open {
        border-bottom-color: #007AFF;
      }
    }

    .dropdown-options {
      border: 1px solid #E5E5E7;
      border-radius: 8px;
      margin-top: 4px;
    }
  }
}

// 颜色变体
.dropdown-container {
  &.color-secondary {
    &.focused,
    &.open {
      .dropdown-wrapper {
        border-color: #5856D6;
        box-shadow: 0 0 0 3px rgba(88, 86, 214, 0.15);
      }
    }

    .dropdown-option.selected {
      background: linear-gradient(135deg, rgba(88, 86, 214, 0.12) 0%, rgba(88, 86, 214, 0.06) 100%);
      color: #5856D6;
    }
  }

  &.color-success {
    &.focused,
    &.open {
      .dropdown-wrapper {
        border-color: #34C759;
        box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.15);
      }
    }

    .dropdown-option.selected {
      background: linear-gradient(135deg, rgba(52, 199, 89, 0.12) 0%, rgba(52, 199, 89, 0.06) 100%);
      color: #34C759;
    }
  }

  &.color-warning {
    &.focused,
    &.open {
      .dropdown-wrapper {
        border-color: #FF9500;
        box-shadow: 0 0 0 3px rgba(255, 149, 0, 0.15);
      }
    }

    .dropdown-option.selected {
      background: linear-gradient(135deg, rgba(255, 149, 0, 0.12) 0%, rgba(255, 149, 0, 0.06) 100%);
      color: #FF9500;
    }
  }

  &.color-error {
    &.focused,
    &.open {
      .dropdown-wrapper {
        border-color: #FF3B30;
        box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.15);
      }
    }

    .dropdown-option.selected {
      background: linear-gradient(135deg, rgba(255, 59, 48, 0.12) 0%, rgba(255, 59, 48, 0.06) 100%);
      color: #FF3B30;
    }
  }
}

// 响应式设计
@media (max-width: 768px) {
  .dropdown-container {
    .dropdown-wrapper {
      min-height: 44px;
    }

    .dropdown-display {
      padding: 10px 14px;
      
      .selected-text {
        font-size: 16px;
      }
    }

    .dropdown-option {
      padding: 14px 16px;
      min-height: 44px;
      
      .option-label {
        font-size: 16px;
      }
    }

    .search-container {
      padding: 16px;
      
      .search-input {
        padding: 12px 16px 12px 44px;
        font-size: 16px; // 防止iOS缩放
      }
    }
  }
}

// 深色模式支持
@media (prefers-color-scheme: dark) {
  .dropdown-container {
    .dropdown-label {
      color: #F2F2F7;
    }

    .dropdown-wrapper {
      background: #1C1C1E;
      border-color: #38383A;

      &:hover:not(.disabled) {
        border-color: #0A84FF;
      }

      &.focused,
      &.open {
        border-color: #0A84FF;
        box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
      }
    }

    .dropdown-display {
      .selected-text {
        color: #F2F2F7;

        &.placeholder {
          color: #8E8E93;
        }
      }

      .clear-button {
        background: #2C2C2E;

        &:hover {
          background: #3A3A3C;
        }
      }
    }

    .dropdown-options {
      background: #1C1C1E;
      border-color: #0A84FF;
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }

    .search-container {
      background: #2C2C2E;
      border-bottom-color: #38383A;

      .search-input {
        background: #1C1C1E;
        border-color: #38383A;
        color: #F2F2F7;

        &:focus {
          border-color: #0A84FF;
        }
      }
    }

    .dropdown-option {
      border-bottom-color: rgba(56, 56, 58, 0.5);
      color: #F2F2F7;

      &:hover:not(.disabled):not(.group-header) {
        background: linear-gradient(135deg, rgba(10, 132, 255, 0.12) 0%, rgba(10, 132, 255, 0.06) 100%);
      }

      &.selected:not(.group-header) {
        background: linear-gradient(135deg, rgba(10, 132, 255, 0.15) 0%, rgba(10, 132, 255, 0.08) 100%);
        color: #0A84FF;
      }

      &.group-header {
        background: #2C2C2E;
        color: #8E8E93;
        border-bottom-color: #38383A;
      }
    }

    .no-options {
      color: #8E8E93;
    }

    .error-message {
      color: #FF453A;
    }

    .help-text {
      color: #8E8E93;
    }
  }
}

// 高对比度模式
@media (prefers-contrast: high) {
  .dropdown-container {
    .dropdown-wrapper {
      border-width: 3px;
    }

    .dropdown-option {
      &.selected:not(.group-header) {
        background: #007AFF;
        color: #FFFFFF;
      }
    }
  }
}

// 减少动画模式
@media (prefers-reduced-motion: reduce) {
  .dropdown-container {
    * {
      transition: none !important;
      animation: none !important;
    }
  }
}