/* ============================================================
   iWinFixBox 工具箱页面 - 重构版
   - flex 两栏（sidebar + right），消灭 grid-stretch
   - loading/error 用 fixed overlay，完全脱离 DOM 流
   - 全新 tp-* 命名，避免旧缓存干扰
   ============================================================ */

/* ---------- 基础 ---------- */
.tools-page { background-color: var(--bg-deep); }

/* 主容器 */
.tp {
  padding-top: 120px;
  padding-bottom: 80px;
  position: relative;
  z-index: 1;
}

.tp-wrap {
  /* 不设额外 padding/margin，依赖 container */
}

/* ---------- 顶部 header ---------- */
.tp-header {
  margin-bottom: 32px;
}

.tp-title h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 800;
  color: var(--text-bright);
  margin: 8px 0 8px;
  letter-spacing: -0.5px;
}

.tp-title p {
  color: var(--text-secondary);
  font-size: 15px;
  margin: 0 0 20px;
}

/* meta 胶囊 */
.tp-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.pill {
  padding: 3px 10px;
  background: var(--bg-faint);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.pill-sep { color: var(--border); }

/* 搜索框 */
.tp-search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-window);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tp-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(60, 130, 168, 0.12);
}

.tp-search svg { color: var(--text-muted); flex-shrink: 0; }

.tp-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-body);
}

.tp-search input::placeholder { color: var(--text-muted); }

/* ---------- Flex 两栏布局 ---------- */
.tp-body {
  display: flex;
  gap: 32px;
  align-items: flex-start;   /* 关键！防止 sidebar 被内容撑高 */
}

/* 左侧分类栏 */
.tp-side {
  flex-shrink: 0;          /* 不被压缩 */
  width: 200px;
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
  align-self: flex-start;   /* 双重保险：高度由内容决定 */
}

.tp-cat {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-body);
  text-align: left;
  line-height: 1;
}

.tp-cat:hover {
  background: var(--bg-hover);
  color: var(--text-bright);
}

.tp-cat.active {
  background: var(--accent);
  color: #fff;
}

.tp-cat.active .tp-count {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.tp-count {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 11px;
  background: var(--bg-hover);
  color: var(--text-muted);
  padding: 1px 8px;
  border-radius: 999px;
  transition: all 0.15s ease;
  line-height: 1;
}

/* 右侧卡片区 */
.tp-right {
  flex: 1;                  /* 占据剩余空间 */
  min-width: 0;             /* 防止 flex 子项溢出 */
}

/* 空状态 */
.tp-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* 卡片网格 */
.tp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  /* 不加额外 padding/margin，保持紧贴 header 下沿 */
}

/* 卡片 */
.tp-card {
  background: var(--bg-window);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
}

.tp-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.tp-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  min-width: 0;              /* flex 子项省略号生效的前提 */
}

.tp-card-ico {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: var(--bg-faint);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

.tp-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-bright);
  line-height: 1.3;
  white-space: nowrap;       /* 强制单行 */
  overflow: hidden;          /* 超出隐藏 */
  text-overflow: ellipsis;   /* 末尾省略号 */
  flex: 1;
  min-width: 0;              /* flex 子项省略号生效的前提 */
}

/* 标题中 [...] / (...) 方括号标签金色高亮（与 app 一致） */
.tp-tag {
  color: #E8B94E;
}

.tp-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.55;
  flex: 1;
}

.tp-card-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.tp-card-foot .btn {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  flex: 1;
  justify-content: center;
}

/* ---------- Overlay（加载 + 错误） ---------- */
.tp-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  z-index: 100;              /* 低于官方 loader（coldsea@cdloader） */
  transition: opacity 0.2s ease;
}

.tp-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.tp-overlay-box {
  text-align: center;
  color: var(--text-muted);
}

.tp-overlay-box p {
  margin: 16px 0 20px;
  font-size: 14px;
}

.tp-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-hover);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto;
  animation: tp-spin 0.8s linear infinite;
}

@keyframes tp-spin {
  to { transform: rotate(360deg); }
}

/* 通用 hidden */
.hidden { display: none !important; }

/* 错误态的文字颜色 */
.tp-overlay.error .tp-overlay-box p { color: var(--danger); }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .tp-body {
    flex-direction: column;
  }

  .tp-side {
    position: static;
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px;
  }

  .tp-side::-webkit-scrollbar { display: none; }

  .tp-cat {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

@media (max-width: 480px) {
  .tp-grid {
    grid-template-columns: 1fr;
  }
}
