/* ========================================
   kb-pages.css — 知识库页面扩展样式
   严格遵循模板 CSS 变量体系
   ======================================== */

/* ---- 加载状态 ---- */
.page-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 40vh;
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- 空状态 ---- */
.page-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 30vh;
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 15px;
}

.page-empty-icon {
  font-size: 48px;
  opacity: 0.4;
}

/* ---- 错误状态 ---- */
.page-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 30vh;
  color: var(--coral);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 15px;
}

/* ---- 类型徽标 ---- */
.type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.6;
}

.type-badge-wiki {
  background: rgba(47, 117, 168, 0.1);
  color: var(--blue);
  border: 1px solid rgba(47, 117, 168, 0.2);
}

.type-badge-article {
  background: rgba(111, 155, 121, 0.1);
  color: var(--green);
  border: 1px solid rgba(111, 155, 121, 0.2);
}

.type-badge-fable {
  background: rgba(197, 161, 91, 0.1);
  color: var(--gold);
  border: 1px solid rgba(197, 161, 91, 0.2);
}

/* ---- 工作空间徽标 ---- */
.ws-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: rgba(31, 54, 68, 0.06);
  color: var(--muted);
}

/* ---- 页面标题区 ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 32px 0 24px;
}

.page-header h2 {
  margin: 0;
  color: #172b39;
  font-size: clamp(26px, 3.5vw, 42px);
  font-weight: 500;
  line-height: 1.1;
}

.page-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ---- 搜索框 ---- */
.search-box {
  position: relative;
  width: 100%;
  max-width: 480px;
}

.search-box input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 220ms ease, box-shadow 220ms ease;
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 117, 168, 0.1);
}

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

.search-box::before {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  content: "🔍";
  font-size: 14px;
  opacity: 0.5;
  pointer-events: none;
}

/* ---- 筛选栏 ---- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 220ms ease;
}

.filter-tag:hover {
  border-color: rgba(47, 117, 168, 0.3);
  color: var(--blue);
}

.filter-tag.active {
  border-color: var(--blue);
  background: rgba(47, 117, 168, 0.08);
  color: var(--blue);
  font-weight: 600;
}

/* ---- 卡片网格 ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.kb-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 16px 42px rgba(50, 82, 94, 0.07);
  transition: transform 260ms ease, box-shadow 260ms ease, border-color 260ms ease;
  cursor: pointer;
}

.kb-card:hover {
  border-color: rgba(47, 117, 168, 0.28);
  box-shadow: 0 22px 68px rgba(42, 75, 91, 0.12);
  transform: translateY(-4px);
}

.kb-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.kb-card-title {
  margin: 0;
  color: #182d3b;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kb-card-excerpt {
  margin: 0 0 auto;
  color: #536371;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kb-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.kb-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}

.kb-card-tag {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(31, 54, 68, 0.05);
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 11px;
}

/* ---- 分页 ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 32px 0 48px;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
}

.pagination button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  transition: all 220ms ease;
}

.pagination button:hover:not(:disabled) {
  border-color: var(--blue);
  color: var(--blue);
}

.pagination button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.pagination button.active {
  border-color: var(--blue);
  background: rgba(47, 117, 168, 0.1);
  color: var(--blue);
  font-weight: 600;
}

.pagination .page-info {
  color: var(--muted);
  font-size: 13px;
  padding: 0 8px;
}

/* ---- 文章详情页 ---- */
.article-page {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 0 64px;
}

.article-header {
  margin-bottom: 32px;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.article-title {
  margin: 0 0 16px;
  color: #172b39;
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 500;
  line-height: 1.25;
}

.article-source {
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 13px;
}

.article-body {
  color: #1f2a33;
  font-size: 17px;
  line-height: 2;
  letter-spacing: 0.015em;
  font-family:
    "Noto Serif SC",
    "Source Han Serif SC",
    "STSong",
    "Songti SC",
    "PingFang SC",
    serif;
}

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  margin: 1.8em 0 0.5em;
  color: #0f1a22;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
  font-family:
    "Noto Serif SC",
    "Source Han Serif SC",
    "STSong",
    "Songti SC",
    "PingFang SC",
    serif;
}

.article-body h1 { font-size: 1.5em; padding-bottom: 0.3em; border-bottom: 1px solid var(--line); }
.article-body h2 { font-size: 1.3em; }
.article-body h3 { font-size: 1.15em; }

.article-body p {
  margin: 0 0 1.4em;
  text-indent: 0;
}

.article-body a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.article-body a:hover {
  color: #1a5a8a;
}

.article-body blockquote {
  margin: 1.5em 0;
  padding: 16px 24px;
  border-left: 3px solid var(--cyan);
  background: linear-gradient(90deg, rgba(117, 199, 217, 0.06), transparent);
  color: #3a4a58;
  font-style: italic;
  font-size: 0.96em;
  line-height: 1.9;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.article-body blockquote p:last-child {
  margin-bottom: 0;
}

.article-body code {
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(31, 54, 68, 0.06);
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.88em;
}

.article-body pre {
  margin: 1.2em 0;
  padding: 16px 20px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(31, 54, 68, 0.04);
  font-size: 14px;
  line-height: 1.6;
}

.article-body pre code {
  padding: 0;
  background: none;
}

.article-body ul,
.article-body ol {
  margin: 0 0 1.2em;
  padding-left: 1.5em;
}

.article-body li {
  margin-bottom: 0.4em;
}

.article-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin: 1.2em 0;
}

.article-body hr {
  margin: 2em 0;
  border: none;
  border-top: 1px solid var(--line);
}

.article-body table {
  width: 100%;
  margin: 1.2em 0;
  border-collapse: collapse;
  font-size: 0.95em;
}

.article-body th,
.article-body td {
  padding: 10px 14px;
  border: 1px solid var(--line);
  text-align: left;
}

.article-body th {
  background: rgba(31, 54, 68, 0.04);
  font-weight: 600;
}

/* ---- 关联文章 ---- */
.related-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.related-section h3 {
  margin: 0 0 16px;
  color: #172b39;
  font-size: 20px;
  font-weight: 500;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.related-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: all 220ms ease;
}

.related-card:hover {
  border-color: rgba(47, 117, 168, 0.28);
  transform: translateY(-2px);
}

.related-card h4 {
  margin: 0 0 6px;
  color: #182d3b;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
}

.related-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---- 实体卡片 ---- */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}

.entity-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 12px 32px rgba(50, 82, 94, 0.06);
  transition: transform 260ms ease, box-shadow 260ms ease;
  cursor: pointer;
}

.entity-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 48px rgba(42, 75, 91, 0.1);
}

.entity-card-name {
  margin: 0 0 6px;
  color: #182d3b;
  font-size: 17px;
  font-weight: 500;
}

.entity-card-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(47, 117, 168, 0.08);
  color: var(--blue);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 11px;
  font-weight: 600;
}

.entity-card-desc {
  margin: 10px 0 0;
  color: #536371;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 13px;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entity-card-count {
  margin-top: 10px;
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 12px;
}

/* ---- 实体详情 ---- */
.entity-page {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 0 64px;
}

.entity-header {
  margin-bottom: 32px;
}

.entity-name {
  margin: 0 0 8px;
  color: #172b39;
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 500;
}

.entity-description {
  color: #3f4f5d;
  font-size: 17px;
  line-height: 1.8;
}

.entity-relations {
  margin-top: 32px;
}

.entity-relations h3 {
  margin: 0 0 16px;
  color: #172b39;
  font-size: 20px;
  font-weight: 500;
}

.relation-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.relation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
}

.relation-arrow {
  color: var(--muted);
  font-size: 14px;
  flex-shrink: 0;
}

.relation-target {
  color: var(--blue);
  font-weight: 500;
  cursor: pointer;
}

.relation-target:hover {
  text-decoration: underline;
}

/* ---- 搜索页面 ---- */
.search-page {
  max-width: 780px;
  margin: 0 auto;
  padding: 32px 0 64px;
}

.search-page .search-box {
  max-width: 100%;
  margin-bottom: 24px;
}

.search-results-count {
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
  margin-bottom: 20px;
}

.search-highlight {
  background: rgba(197, 161, 91, 0.2);
  padding: 0 2px;
  border-radius: 2px;
}

/* ---- 知识寓言 ---- */
.fable-card {
  position: relative;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(255, 248, 242, 0.62)),
    radial-gradient(circle at 84% 16%, rgba(220, 126, 110, 0.12), transparent 15rem);
  box-shadow: 0 16px 42px rgba(50, 82, 94, 0.07);
  transition: transform 260ms ease;
  cursor: pointer;
}

.fable-card:hover {
  transform: translateY(-3px);
}

.fable-card::before {
  position: absolute;
  top: 12px;
  right: 16px;
  content: "📜";
  font-size: 24px;
  opacity: 0.3;
}

.fable-card h3 {
  margin: 0 0 12px;
  color: #182d3b;
  font-size: 20px;
  font-weight: 500;
  line-height: 1.3;
}

.fable-card p {
  margin: 0;
  color: #536371;
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.8;
}

.fable-card .fable-moral {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid rgba(220, 126, 110, 0.2);
  color: var(--coral);
  font-style: italic;
  font-size: 14px;
}

/* ---- 专题详情 ---- */
.topic-detail-header {
  margin-bottom: 24px;
}

.topic-detail-header h2 {
  margin: 0 0 8px;
  color: #172b39;
  font-size: clamp(26px, 3.5vw, 42px);
  font-weight: 500;
}

.topic-detail-header p {
  margin: 0;
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
}

/* ---- 返回按钮 ---- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: color 220ms ease;
}

.back-link:hover {
  color: var(--blue);
}

/* ---- 登录提示 ---- */
.auth-required {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 40vh;
  text-align: center;
  padding: 40px 20px;
}

.auth-required-icon {
  font-size: 48px;
  opacity: 0.5;
}

.auth-required h3 {
  margin: 0;
  color: #172b39;
  font-size: 20px;
  font-weight: 500;
}

.auth-required p {
  margin: 0;
  color: var(--muted);
  font-family: "PingFang SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
  max-width: 400px;
  line-height: 1.7;
}

/* ---- 响应式 ---- */
@media (max-width: 980px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }

  .entity-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }

  .article-page,
  .entity-page,
  .search-page {
    padding: 24px 0 48px;
  }
}

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

  .entity-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-header-actions {
    width: 100%;
  }

  .page-header-actions .search-box {
    max-width: 100%;
  }

  .article-body {
    font-size: 16px;
  }

  .article-body pre {
    font-size: 13px;
    padding: 12px 16px;
  }

  .related-grid {
    grid-template-columns: 1fr;
  }

  .filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .filter-tag {
    flex-shrink: 0;
  }
}
