/* ============================================
   FilePreviewHeader - 文件预览面板 Header 样式
   类名前缀: wk-file-preview-header
   ============================================ */

.wk-file-preview-header {
  height: var(--wk-sp-12);
  min-height: var(--wk-sp-12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--wk-sp-4);
  border-bottom: 1px solid var(--wk-border-default);
  background-color: var(--wk-bg-surface);
  border-radius: var(--wk-r-md) var(--wk-r-md) 0 0;
}

/* ============================================
   左侧区域：文件选择器 + 视图切换
   ============================================ */

.wk-file-preview-header__left {
  display: flex;
  align-items: center;
  gap: var(--wk-sp-1);
  flex-shrink: 0;
  min-width: 0;
  max-width: 150px;
}

/* 通用按钮样式 */
.wk-file-preview-header__btn {
  width: var(--wk-sp-4);
  height: var(--wk-sp-4);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--wk-icon-muted);
  transition: color var(--wk-dur-fast);
  flex-shrink: 0;
}

.wk-file-preview-header__btn:hover {
  color: var(--wk-text-primary);
}

/* 激活状态（如 TOC 按钮展开时） */
.wk-file-preview-header__btn--active {
  color: var(--wk-brand-primary);
}

.wk-file-preview-header__btn--active:hover {
  color: var(--wk-brand-primary);
}

.wk-file-preview-header__btn--close:hover {
  color: var(--wk-color-danger);
}

/* 返回按钮 */
.wk-file-preview-header__btn--back {
  margin-right: var(--wk-sp-1);
}

/* ============================================
   文件下拉选择器
   ============================================ */

.wk-file-preview-header__dropdown {
  position: relative;
}

.wk-file-preview-header__dropdown-btn {
  display: flex;
  align-items: center;
  gap: var(--wk-sp-1);
  padding: 0;
  border: none;
  background: transparent;
  border-radius: var(--wk-r-sm);
  cursor: default;
  color: var(--wk-text-primary);
  font-size: var(--wk-text-size-md);
  font-weight: var(--wk-font-medium);
  transition: background var(--wk-dur-fast);
  max-width: 150px;
  min-width: 0;
}

/* 有文件列表时显示可点击状态 */
.wk-file-preview-header__dropdown-btn--has-files {
  cursor: pointer;
}

.wk-file-preview-header__dropdown-btn--has-files:hover {
  opacity: 0.8;
}

.wk-file-preview-header__dropdown-btn > svg:first-child {
  flex-shrink: 0;
  color: var(--wk-text-secondary);
}

/* 文件类型图标 */
.wk-file-preview-header__file-icon {
  width: var(--wk-sp-4);
  height: var(--wk-sp-4);
  flex-shrink: 0;
  object-fit: contain;
}

.wk-file-preview-header__dropdown-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 110px;
  line-height: var(--wk-sp-5);
}

.wk-file-preview-header__dropdown-caret {
  flex-shrink: 0;
  transition: transform 0.15s;
  color: var(--wk-text-tertiary);
}

.wk-file-preview-header__dropdown-caret--open {
  transform: rotate(180deg);
}

/* 下拉面板 */
.wk-file-preview-header__dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 240px;
  max-width: 320px;
  background: var(--wk-bg-elevated);
  border: 1px solid var(--wk-border-default);
  border-radius: var(--wk-r-md);
  box-shadow: var(--wk-shadow-lg);
  z-index: 1000;
  overflow: hidden;
}

.wk-file-preview-header__dropdown-list {
  max-height: 280px;
  overflow-y: auto;
  padding: var(--wk-sp-1) 0;
}

.wk-file-preview-header__dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--wk-sp-2);
  padding: var(--wk-sp-2) var(--wk-sp-3);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.wk-file-preview-header__dropdown-item:hover {
  background: var(--wk-bg-hover);
}

.wk-file-preview-header__dropdown-item--active {
  background: var(--wk-bg-active);
}

.wk-file-preview-header__dropdown-item--active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--wk-color-primary);
  border-radius: 0 2px 2px 0;
}

.wk-file-preview-header__dropdown-item-badge {
  font-size: var(--wk-text-size-xs);
  flex-shrink: 0;
}

.wk-file-preview-header__dropdown-item-icon {
  color: var(--wk-text-secondary);
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 缩略图模式 */
.wk-file-preview-header__dropdown-item-icon--thumbnail {
  width: 28px;
  height: 28px;
  border-radius: var(--wk-r-xs);
  overflow: hidden;
  background: var(--wk-bg-elevated);
}

.wk-file-preview-header__dropdown-item-thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wk-file-preview-header__dropdown-item-name {
  flex: 1;
  font-size: var(--wk-text-size-base);
  color: var(--wk-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 加载更多 */
.wk-file-preview-header__dropdown-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--wk-sp-2);
  color: var(--wk-text-tertiary);
  font-size: var(--wk-text-size-sm);
}

/* 没有更多数据 */
.wk-file-preview-header__dropdown-no-more {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--wk-sp-2);
  color: var(--wk-text-quaternary);
  font-size: var(--wk-text-size-xs);
}

/* ============================================
   分隔符
   ============================================ */

.wk-file-preview-header__sep {
  width: 1px;
  height: var(--wk-sp-3);
  background: var(--wk-border-default);
  border-radius: var(--wk-r-full);
  flex-shrink: 0;
}

/* ============================================
   视图切换（预览/源码）
   ============================================ */

.wk-file-preview-header__view-toggle {
  display: flex;
  align-items: center;
  gap: var(--wk-sp-1);
  background: var(--wk-bg-tab);
  border-radius: var(--wk-r-full);
  padding: var(--wk-sp-0-5);
}

.wk-file-preview-header__view-toggle-btn {
  width: var(--wk-sp-10);
  height: var(--wk-sp-4);
  padding: var(--wk-sp-0-5) var(--wk-sp-2);
  border: none;
  background: transparent;
  border-radius: var(--wk-r-full);
  cursor: pointer;
  font-size: var(--wk-text-size-tiny);
  font-weight: var(--wk-font-medium);
  color: var(--wk-icon-muted);
  transition: background var(--wk-dur-fast), color var(--wk-dur-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.wk-file-preview-header__view-toggle-btn:hover {
  color: var(--wk-text-primary);
}

.wk-file-preview-header__view-toggle-btn--active {
  background: var(--wk-bg-surface);
  color: var(--wk-text-primary);
  border-radius: var(--wk-r-full);
}

/* ============================================
   右侧区域：操作按钮
   ============================================ */

.wk-file-preview-header__actions {
  display: flex;
  align-items: center;
  gap: var(--wk-sp-4);
  flex-shrink: 0;
}

/* ============================================
   响应式：小屏幕隐藏部分按钮
   ============================================ */

/* 暗色主题适配 */
body[theme-mode="dark"] .wk-file-preview-header__btn {
  color: var(--wk-white-alpha-40);
}

body[theme-mode="dark"] .wk-file-preview-header__btn:hover {
  color: var(--wk-text-primary);
}

body[theme-mode="dark"] .wk-file-preview-header__view-toggle {
  background: var(--wk-white-alpha-07);
}

body[theme-mode="dark"] .wk-file-preview-header__view-toggle-btn {
  color: var(--wk-white-alpha-40);
}

body[theme-mode="dark"] .wk-file-preview-header__view-toggle-btn--active {
  background: var(--wk-white-alpha-12);
  color: var(--wk-color-white);
}

body[theme-mode="dark"] .wk-file-preview-header__sep {
  background: var(--wk-white-alpha-12);
}

@media (max-width: 480px) {
  .wk-file-preview-header__dropdown-text {
    max-width: 80px;
  }

  .wk-file-preview-header__view-toggle {
    display: none;
  }

  .wk-file-preview-header__sep {
    display: none;
  }
}
