.contacts-page {
  display: flex;
  height: calc(100% + 48px);
  margin: -24px;
  background: var(--bg-primary);
  overflow: hidden;

  // 左侧联系人面板
  .contacts-panel {
    width: 350px;
    min-width: 350px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--card-bg);
  }

  .panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);

    h2 {
      font-size: 18px;
      font-weight: 600;
      color: var(--text-primary);
      margin: 0;
    }

    .icon-btn {
      width: 32px;
      height: 32px;
      border: none;
      background: var(--bg-tertiary);
      border-radius: 8px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      color: var(--text-secondary);
      transition: all 0.2s;

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

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

      .spin {
        animation: contactsSpin 1s linear infinite;
      }

      &.export-mode-btn.active {
        background: var(--primary);
        color: #fff;
      }
    }
  }

  .search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 20px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;

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

    svg {
      color: var(--text-tertiary);
      flex-shrink: 0;
    }

    input {
      flex: 1;
      border: none;
      background: none;
      outline: none;
      font-size: 14px;
      color: var(--text-primary);

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

    .clear-btn {
      background: none;
      border: none;
      padding: 4px;
      cursor: pointer;
      color: var(--text-tertiary);
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 4px;

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

  .type-filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 20px 16px;
    max-width: 300px;

    &::-webkit-scrollbar {
      display: none;
    }

    .filter-chip {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 8px 14px;
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      border-radius: 10px;
      cursor: pointer;
      user-select: none;
      font-size: 13px;
      font-weight: 500;
      color: var(--text-secondary);
      transition: all 0.2s ease;
      white-space: nowrap;

      input[type="checkbox"] {
        display: none;
      }

      svg {
        opacity: 0.7;
        transition: transform 0.2s;
        flex-shrink: 0;
      }

      .chip-label {
        min-width: 0;
      }

      .chip-count {
        margin-left: auto;
        text-align: right;
        font-variant-numeric: tabular-nums;
      }

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

        svg {
          transform: translateY(-1px);
        }
      }

      &.active {
        background: var(--primary-light);
        border-color: var(--primary);
        color: var(--primary);

        svg {
          opacity: 1;
          color: var(--primary);
        }
      }
    }
  }

  .contacts-count {
    padding: 0 20px 12px;
    font-size: 13px;
    color: var(--text-secondary);

    .contacts-cache-meta {
      margin-left: 10px;
      color: var(--text-tertiary);
      font-size: 12px;

      &.syncing {
        color: var(--primary);
      }
    }

    .avatar-enrich-progress {
      margin-left: 10px;
      color: var(--text-tertiary);
      font-size: 12px;
    }
  }

  .selection-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 20px 12px;

    .checkbox-item {
      font-size: 13px;
      color: var(--text-secondary);
    }

    .selection-count {
      font-size: 12px;
      color: var(--text-tertiary);
    }
  }

  .loading-state,
  .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-tertiary);
    font-size: 14px;

    .spin {
      animation: contactsSpin 1s linear infinite;
    }
  }

  .load-issue-state {
    flex: 1;
    padding: 14px 14px 18px;
    overflow-y: auto;
  }

  .issue-card {
    border: 1px solid color-mix(in srgb, var(--danger, #ef4444) 45%, var(--border-color));
    background: color-mix(in srgb, var(--danger, #ef4444) 8%, var(--card-bg));
    border-radius: 12px;
    padding: 14px;
    color: var(--text-primary);

    .issue-title {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 14px;
      font-weight: 600;
      color: color-mix(in srgb, var(--danger, #ef4444) 85%, var(--text-primary));
      margin-bottom: 8px;
    }

    .issue-message {
      margin: 0 0 8px;
      font-size: 13px;
      color: var(--text-secondary);
      line-height: 1.5;
    }

    .issue-reason {
      margin: 0;
      font-size: 13px;
      color: var(--text-secondary);
      line-height: 1.5;
    }

    .issue-hints {
      margin: 10px 0 0;
      padding-left: 18px;
      font-size: 12px;
      color: var(--text-tertiary);
      line-height: 1.6;
    }

    .issue-actions {
      margin-top: 12px;
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }

    .issue-btn {
      border: 1px solid var(--border-color);
      background: var(--bg-secondary);
      border-radius: 8px;
      padding: 7px 10px;
      font-size: 12px;
      color: var(--text-secondary);
      display: inline-flex;
      align-items: center;
      gap: 6px;
      cursor: pointer;
      transition: all 0.2s ease;

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

      &.primary {
        background: color-mix(in srgb, var(--primary) 14%, var(--bg-secondary));
        border-color: color-mix(in srgb, var(--primary) 42%, var(--border-color));
        color: var(--primary);
      }
    }

    .issue-diagnostics {
      margin-top: 12px;
      border-radius: 8px;
      background: var(--bg-primary);
      border: 1px dashed var(--border-color);
      padding: 10px;
      font-size: 12px;
      line-height: 1.5;
      color: var(--text-secondary);
      white-space: pre-wrap;
      word-break: break-word;
    }
  }

  .contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px;
    position: relative;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-thumb {
      background: var(--text-tertiary);
      border-radius: 3px;
      opacity: 0.3;
    }
  }

  .contacts-list-virtual {
    position: relative;
    min-height: 100%;
  }

  .contact-row {
    position: absolute;
    left: 0;
    right: 0;
    height: 76px;
    padding-bottom: 4px;
    will-change: transform;
  }

  .contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    height: 72px;
    box-sizing: border-box;
    border-radius: 10px;
    transition: all 0.2s;
    cursor: pointer;
    margin-bottom: 0;

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

    &.selected {
      background: color-mix(in srgb, var(--primary) 12%, transparent);
    }

    &.active {
      background: var(--bg-tertiary);
    }

    .contact-select {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;

      input[type="checkbox"] {
        width: 16px;
        height: 16px;
        cursor: pointer;
        accent-color: var(--primary);
      }
    }

    .contact-avatar {
      width: 44px;
      height: 44px;
      border-radius: 10px;
      background: linear-gradient(135deg, var(--primary), var(--primary-hover));
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      flex-shrink: 0;

      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }

      span {
        color: #fff;
        font-size: 16px;
        font-weight: 600;
      }
    }

    .contact-info {
      flex: 1;
      min-width: 0;
    }

    .contact-name {
      font-size: 14px;
      font-weight: 500;
      color: var(--text-primary);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .contact-remark {
      font-size: 12px;
      color: var(--text-tertiary);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-top: 2px;
    }

    .contact-type {
      display: flex;
      align-items: center;
      gap: 4px;
      padding: 4px 10px;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 500;
      flex-shrink: 0;

      &.friend {
        background: rgba(var(--primary-rgb), 0.1);
        color: var(--primary);
      }

      &.group {
        background: rgba(52, 211, 153, 0.1);
        color: rgb(52, 211, 153);
      }

      &.official {
        background: rgba(251, 191, 36, 0.1);
        color: rgb(251, 191, 36);
      }

      svg {
        flex-shrink: 0;
      }
    }
  }

  // 右侧详情面板内的联系人资料
  .detail-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;

    .detail-avatar {
      width: 80px;
      height: 80px;
      border-radius: 16px;
      background: linear-gradient(135deg, var(--primary), var(--primary-hover));
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;

      img { width: 100%; height: 100%; object-fit: cover; }
      span { color: #fff; font-size: 28px; font-weight: 600; }
    }

    .detail-name {
      font-size: 18px;
      font-weight: 600;
      color: var(--text-primary);
    }
  }

  .detail-info-list {
    margin-bottom: 24px;

    .detail-row {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 10px 0;
      font-size: 13px;
      border-bottom: 1px solid var(--border-color);

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

    .detail-label {
      color: var(--text-tertiary);
      min-width: 48px;
      flex-shrink: 0;
    }

    .detail-value {
      color: var(--text-primary);
      word-break: break-all;
      user-select: text;
    }

    .detail-entry-btn {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      margin-left: auto;
      border: 1px solid var(--border-color);
      border-radius: 8px;
      background: var(--bg-secondary);
      color: var(--text-primary);
      padding: 6px 10px;
      font-size: 12px;
      line-height: 1;
      cursor: pointer;
      transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;

      &:hover {
        color: var(--primary);
        border-color: color-mix(in srgb, var(--primary) 45%, var(--border-color));
        background: color-mix(in srgb, var(--primary) 8%, var(--bg-secondary));
      }
    }
  }

  .goto-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;

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

  .empty-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-tertiary);
    font-size: 14px;
  }

  // 右侧设置面板
  .settings-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-thumb {
      background: var(--text-tertiary);
      border-radius: 3px;
    }
  }

  .setting-section {
    margin-bottom: 28px;

    h3 {
      font-size: 13px;
      font-weight: 600;
      color: var(--text-secondary);
      text-transform: uppercase;
      letter-spacing: 0.5px;
      margin: 0 0 14px;
    }
  }

  .format-select {
    position: relative;
    /* margin-bottom 移到 .setting-section */

    .select-trigger {
      width: 100%;
      padding: 10px 16px;
      border: 1px solid var(--border-color);
      border-radius: 9999px;
      /* Rounded pill shape */
      font-size: 14px;
      background: var(--bg-primary);
      color: var(--text-primary);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
      cursor: pointer;
      transition: all 0.2s;

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

      &.open {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
      }
    }

    .select-value {
      flex: 1;
      min-width: 0;
      text-align: left;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .select-dropdown {
      position: absolute;
      top: calc(100% + 6px);
      left: 0;
      right: 0;
      background: color-mix(in srgb, var(--bg-primary) 85%, var(--bg-secondary));
      border: 1px solid var(--border-color);
      border-radius: 12px;
      padding: 6px;
      box-shadow: var(--shadow-md);
      z-index: 20;
      max-height: 260px;
      overflow-y: auto;
      backdrop-filter: blur(14px);
      -webkit-backdrop-filter: blur(14px);
    }

    .select-option {
      width: 100%;
      text-align: left;
      display: flex;
      flex-direction: column;
      gap: 4px;
      padding: 10px 12px;
      border: none;
      border-radius: 10px;
      background: transparent;
      cursor: pointer;
      transition: all 0.15s;
      color: var(--text-primary);
      font-size: 14px;

      &:hover {
        background: var(--bg-tertiary);
      }

      &.active {
        background: color-mix(in srgb, var(--primary) 12%, transparent);
        color: var(--primary);

        .option-desc {
          color: var(--primary);
        }
      }
    }

    .option-label {
      font-weight: 500;
    }

    .option-desc {
      font-size: 12px;
      color: var(--text-tertiary);
    }
  }

  .checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);

    input[type="checkbox"] {
      width: 18px;
      height: 18px;
      accent-color: var(--primary);
      cursor: pointer;
    }
  }

  .export-path-display {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 12px;

    svg {
      color: var(--primary);
      flex-shrink: 0;
    }

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

  .select-folder-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;

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

      svg {
        color: var(--primary);
      }
    }

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

    svg {
      color: var(--text-secondary);
      transition: color 0.2s;
    }
  }

  .export-action {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
  }

  .export-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;

    &:hover:not(:disabled) {
      background: var(--primary-hover);
    }

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

    .spin {
      animation: contactsSpin 1s linear infinite;
    }
  }
}

@keyframes contactsSpin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}
