@use '../styles/variables' as *;
@use '../styles/mixins' as *;

.container {
  display: flex;
  flex-direction: column;
  gap: $spacing-lg;
}

.pageHeader {
  display: flex;
  flex-direction: column;
  gap: $spacing-sm;
}

.pageTitle {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.description {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

.headerActions {
  display: flex;
  gap: $spacing-sm;
  flex-wrap: wrap;
}

.titleWrapper {
  display: flex;
  align-items: center;
  gap: $spacing-sm;
  line-height: 24px;
}

.countBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  min-width: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--count-badge-text);
  background-color: var(--count-badge-bg);
  box-sizing: border-box;
}

.errorBox {
  padding: $spacing-md;
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--danger-color);
  border-radius: $radius-md;
  color: var(--danger-color);
  font-size: 14px;
  margin-bottom: $spacing-md;
}

// 筛选区域
.filterSection {
  display: flex;
  flex-direction: column;
  gap: $spacing-md;
  margin-bottom: $spacing-lg;
}

.filterTags {
  display: flex;
  flex-wrap: wrap;
  gap: $spacing-xs;
}

.filterTag {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all $transition-fast;

  &:hover {
    transform: translateY(-1px);
    box-shadow: $shadow-sm;
  }
}

.filterTagActive {
  font-weight: 600;
}

.filterControls {
  display: flex;
  gap: $spacing-md;
  flex-wrap: wrap;
  align-items: flex-end;

  // 修复 Input 组件在 filterItem 中的嵌套样式
  :global(.form-group) {
    margin: 0;
  }

  :global(.input) {
    height: 38px;
    box-sizing: border-box;
  }
}

.filterItem {
  display: flex;
  flex-direction: column;
  gap: 4px;

  label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
  }

  // 搜索输入框需要更宽以显示完整的 placeholder
  &:first-child {
    min-width: 220px;
    flex: 1;
    max-width: 320px;
  }

  // 其他 filterItem 保持较小的宽度
  &:not(:first-child) {
    min-width: auto;
  }
}

.pageSizeSelect {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: $radius-md;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  cursor: text;
  height: 38px;
  box-sizing: border-box;

  &:focus {
    outline: none;
    border-color: var(--primary-color);
  }
}

// 卡片网格
.fileGrid {
  display: grid;
  gap: $spacing-md;
  grid-template-columns: repeat(3, minmax(0, 1fr));

  @include tablet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @include mobile {
    grid-template-columns: 1fr;
  }
}

.antigravityGrid {
  display: grid;
  gap: $spacing-md;
  grid-template-columns: repeat(3, minmax(0, 1fr));

  @include tablet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @include mobile {
    grid-template-columns: 1fr;
  }
}

.codexGrid {
  display: grid;
  gap: $spacing-md;
  grid-template-columns: repeat(3, minmax(0, 1fr));

  @include tablet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @include mobile {
    grid-template-columns: 1fr;
  }
}

.geminiCliGrid {
  display: grid;
  gap: $spacing-md;
  grid-template-columns: repeat(3, minmax(0, 1fr));

  @include tablet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  @include mobile {
    grid-template-columns: 1fr;
  }
}

.antigravityControls {
  display: flex;
  gap: $spacing-md;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: $spacing-md;
}

.antigravityControl {
  display: flex;
  flex-direction: column;
  gap: 4px;

  label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
  }
}

.codexControls {
  display: flex;
  gap: $spacing-md;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: $spacing-md;
}

.codexControl {
  display: flex;
  flex-direction: column;
  gap: 4px;

  label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
  }
}

.geminiCliControls {
  display: flex;
  gap: $spacing-md;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: $spacing-md;
}

.geminiCliControl {
  display: flex;
  flex-direction: column;
  gap: 4px;

  label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
  }
}

.antigravityCard {
  background-image: linear-gradient(
    180deg,
    rgba(224, 247, 250, 0.12),
    rgba(224, 247, 250, 0)
  );
}

.codexCard {
  background-image: linear-gradient(
    180deg,
    rgba(255, 243, 224, 0.18),
    rgba(255, 243, 224, 0)
  );
}

.geminiCliCard {
  background-image: linear-gradient(
    180deg,
    rgba(231, 239, 255, 0.2),
    rgba(231, 239, 255, 0)
  );
}

.quotaSection {
  display: flex;
  flex-direction: column;
  gap: $spacing-sm;
  padding-top: $spacing-sm;
  margin-top: $spacing-xs;
  border-top: 1px dashed var(--border-color);
}

.quotaRow {
  display: flex;
  flex-direction: column;
  gap: $spacing-xs;
}

.quotaRowHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: $spacing-sm;
  min-width: 0;

  @include mobile {
    flex-direction: column;
    align-items: flex-start;
  }
}

.quotaModel {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;

  @include mobile {
    white-space: normal;
  }
}

.quotaBar {
  height: 8px;
  background-color: var(--bg-tertiary);
  border-radius: 999px;
  overflow: hidden;
}

.quotaBarFill {
  height: 100%;
  background-color: var(--success-color, #22c55e);
  transition: width 0.2s ease;
}

.quotaBarFillHigh {
  background-color: var(--success-color, #22c55e);
}

.quotaBarFillMedium {
  background-color: var(--warning-color, #f59e0b);
}

.quotaBarFillLow {
  background-color: var(--danger-color, #ef4444);
}

.quotaMeta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;

  @include mobile {
    justify-content: flex-start;
  }
}

.quotaPercent {
  font-weight: 600;
  color: var(--text-primary);
}

.quotaReset {
  color: var(--text-tertiary);
}

.quotaAmount {
  color: var(--text-secondary);
}

.quotaMessage {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
  padding: $spacing-sm 0;
}

.quotaError {
  font-size: 12px;
  color: var(--danger-color);
  background-color: rgba(239, 68, 68, 0.08);
  border: 1px solid var(--danger-color);
  border-radius: $radius-sm;
  padding: $spacing-xs $spacing-sm;
}

.quotaWarning {
  font-size: 12px;
  color: var(--warning-color, #f59e0b);
  background-color: rgba(245, 158, 11, 0.12);
  border: 1px solid var(--warning-color, #f59e0b);
  border-radius: $radius-sm;
  padding: $spacing-xs $spacing-sm;
}

.codexPlan {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.codexPlanLabel {
  color: var(--text-tertiary);
}

.codexPlanValue {
  font-weight: 600;
  color: var(--text-primary);
  text-transform: capitalize;
}

// 单个认证文件卡片
.fileCard {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: $radius-lg;
  padding: $spacing-md;
  display: flex;
  flex-direction: column;
  gap: $spacing-sm;
  transition: transform $transition-fast, box-shadow $transition-fast, border-color $transition-fast;

  &:hover {
    transform: translateY(-2px);
    box-shadow: $shadow-md;
    border-color: rgba(37, 99, 235, 0.2);
  }
}

.cardHeader {
  display: flex;
  align-items: center;
  gap: $spacing-sm;
  min-height: 28px;
}

.typeBadge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.fileName {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
  line-height: 1.4;
}

.cardMeta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: $spacing-xs 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.cardStats {
  display: flex;
  flex-wrap: wrap;
  gap: $spacing-sm;
  padding-top: $spacing-xs;
  margin-top: $spacing-xs;
}

.statPill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.1;
  border: 1px solid transparent;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  white-space: nowrap;
}

.statSuccess {
  background-color: var(--success-badge-bg, #d1fae5);
  color: var(--success-badge-text, #065f46);
  border-color: var(--success-badge-border, #6ee7b7);
}

.statFailure {
  background-color: var(--failure-badge-bg, #fee2e2);
  color: var(--failure-badge-text, #991b1b);
  border-color: var(--failure-badge-border, #fca5a5);
}

// 状态监测栏
.statusBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  max-width: 280px;
}

.statusBlocks {
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 180px;
}

.statusBlock {
  flex: 1;
  height: 8px;
  border-radius: 2px;
  min-width: 6px;
  transition: transform 0.15s ease, opacity 0.15s ease;

  &:hover {
    transform: scaleY(1.5);
    opacity: 0.85;
  }
}

.statusBlockSuccess {
  background-color: var(--success-color, #22c55e);
}

.statusBlockFailure {
  background-color: var(--danger-color, #ef4444);
}

.statusBlockMixed {
  background-color: var(--warning-color, #f59e0b);
}

.statusBlockIdle {
  background-color: var(--border-secondary, #e5e7eb);
}

.statusRate {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-tertiary);
}

.statusRateHigh {
  color: var(--success-badge-text, #065f46);
  background: var(--success-badge-bg, #d1fae5);
}

.statusRateMedium {
  color: var(--warning-text, #92400e);
  background: var(--warning-bg, #fef3c7);
}

.statusRateLow {
  color: var(--failure-badge-text, #991b1b);
  background: var(--failure-badge-bg, #fee2e2);
}

.cardActions {
  display: flex;
  gap: $spacing-xs;
  justify-content: flex-end;
  margin-top: auto;
  padding-top: $spacing-sm;
}

.iconButton:global(.btn.btn-sm) {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  box-sizing: border-box;
  border-radius: 6px;
  gap: 0;
}

.actionIcon {
  display: block;
}

.virtualBadge {
  font-size: 12px;
  color: var(--text-secondary);
  background-color: var(--bg-tertiary);
  padding: 4px 10px;
  border-radius: $radius-sm;
  font-style: italic;
  display: inline-flex;
  align-items: center;
}

// 分页
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: $spacing-md;
  margin-top: $spacing-lg;
  padding-top: $spacing-md;
  border-top: 1px solid var(--border-color);
}

.pageInfo {
  font-size: 13px;
  color: var(--text-secondary);
  padding: $spacing-xs $spacing-md;
  background-color: var(--bg-secondary);
  border-radius: $radius-md;
}

// OAuth 排除列表
.excludedList {
  display: flex;
  flex-direction: column;
  gap: $spacing-sm;
}

.excludedItem {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: $spacing-md;
  background-color: var(--bg-secondary);
  border-radius: $radius-md;
  border: 1px solid var(--border-color);
  gap: $spacing-md;

  @include mobile {
    flex-direction: column;
    align-items: flex-start;
  }
}

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

.excludedProvider {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
}

.excludedModels {
  font-size: 12px;
  color: var(--text-secondary);
}

.excludedActions {
  display: flex;
  gap: $spacing-xs;
  flex-shrink: 0;
}

// OAuth 排除列表表单：提供商快捷标签
.providerField {
  display: flex;
  flex-direction: column;
  gap: $spacing-xs;

  :global(.form-group) {
    margin-bottom: 0;
  }
}

.providerTagList {
  display: flex;
  flex-wrap: wrap;
  gap: $spacing-xs;
}

.providerTag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: $radius-full;
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all $transition-fast;

  &:hover {
    border-color: var(--primary-color);
    color: var(--text-primary);
    background-color: var(--bg-hover);
  }

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

.providerTagActive {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;

  &:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
  }
}

// OAuth 模型映射表单
.mappingRow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto auto;
  align-items: center;
  gap: $spacing-sm;

  @include mobile {
    grid-template-columns: 1fr;
  }
}

.mappingSeparator {
  color: var(--text-secondary);
  text-align: center;

  @include mobile {
    display: none;
  }
}

.mappingFork {
  display: flex;
  align-items: center;
}

// 详情弹窗
.detailContent {
  max-height: 400px;
  overflow: auto;
}

.jsonContent {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: $radius-md;
  padding: $spacing-md;
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-primary);
  margin: 0;
}

// 表单
.formGroup {
  display: flex;
  flex-direction: column;
  gap: $spacing-xs;
  margin-top: $spacing-md;

  label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
  }
}

.textarea {
  width: 100%;
  padding: $spacing-sm $spacing-md;
  border: 1px solid var(--border-color);
  border-radius: $radius-md;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  font-family: monospace;
  resize: vertical;

  &:focus {
    outline: none;
    border-color: var(--primary-color);
  }

  &::placeholder {
    color: var(--text-tertiary);
  }
}

.hint {
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  text-align: center;
  padding: $spacing-lg;
}

// 模型列表弹窗
.modelsList {
  display: flex;
  flex-direction: column;
  gap: $spacing-sm;
}

.modelItem {
  display: flex;
  align-items: center;
  gap: $spacing-sm;
  padding: $spacing-sm $spacing-md;
  background-color: var(--bg-secondary);
  border-radius: $radius-md;
  border: 1px solid var(--border-color);
  flex-wrap: wrap;
  cursor: pointer;
  transition: all $transition-fast;

  &:hover {
    background-color: var(--bg-hover);
    border-color: var(--primary-color);
  }

  &:active {
    transform: scale(0.98);
  }
}

.modelId {
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}

.modelDisplayName {
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.modelType {
  font-size: 11px;
  color: var(--text-tertiary);
  background-color: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
  margin-left: auto;
}

.modelItemExcluded {
  opacity: 0.6;
  background-color: var(--bg-tertiary);
  border-style: dashed;

  .modelId {
    text-decoration: line-through;
    color: var(--text-tertiary);
  }

  &:hover {
    border-color: var(--danger-color);
  }
}

.modelExcludedBadge {
  font-size: 10px;
  color: var(--danger-color);
  background-color: rgba(239, 68, 68, 0.1);
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid var(--danger-color);
  flex-shrink: 0;
}
