/* 知识库外壳：左侧栏（日历 + 标签树）+ 右侧内容。
   只读浏览层，无登录、无服务端。与 heartopia-design-tokens.css 的珊瑚色变量共存。 */

/* ---------- 覆盖 Heartopia 语义块的整屏/大间距布局 ----------
   校验脚本要求首页与 shell 保留 heartopia-hero / heartopia-section 这些 class，
   但它们原设计是「整屏 hero + 100px 分节」，知识库要紧凑排版，这里做定点覆盖。 */
main.kb-main-shell { overflow: visible; } /* overflow:hidden 会让 sticky 侧栏失效 */
.kb-main .heartopia-hero.kb-hero {
  display: block;
  min-height: 0;
  padding: 22px 24px;
  overflow: visible;
  align-items: stretch;
}
.kb-main .heartopia-section.kb-section { padding: 0; }

.kb-root {
  --kb-sidebar: 264px;
  --kb-gap: 28px;
  display: grid;
  grid-template-columns: var(--kb-sidebar) minmax(0, 1fr);
  gap: var(--kb-gap);
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  align-items: start;
}

/* ---------- 左侧栏 ---------- */
.kb-sidebar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--site-surface, #fff);
  border: 1px solid var(--site-line, #efe0d6);
  border-radius: 14px;
  padding: 14px;
  font-size: 0.86rem;
  scrollbar-width: thin;
}
.kb-side-block + .kb-side-block { margin-top: 18px; }
.kb-side-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--site-text-muted, #66605a);
  margin-bottom: 8px;
  font-weight: 700;
}
.kb-nav-list { display: flex; flex-direction: column; gap: 2px; }
.kb-nav-list a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--site-text, #2b2620);
  text-decoration: none;
}
.kb-nav-list a:hover, .kb-nav-list a:focus-visible { background: #fff1e9; color: #a04630; }
.kb-nav-list a.is-active { background: #ffe2d6; color: #a04630; font-weight: 700; }
.kb-nav-count { margin-left: auto; font-size: 0.75rem; color: var(--site-text-muted, #66605a); font-variant-numeric: tabular-nums; }

.kb-search-box {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--site-line, #efe0d6);
  border-radius: 9px;
  font-size: 0.85rem;
  background: #fffdfb;
  color: var(--site-text, #2b2620);
}
.kb-search-box:focus { outline: 2px solid #ffd3c4; border-color: #e4593a; }
.kb-search-results { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.kb-search-results a { display: block; padding: 6px 8px; border-radius: 8px; text-decoration: none; color: var(--site-text, #2b2620); border: 1px solid transparent; }
.kb-search-results a:hover { background: #fff1e9; border-color: #ffd3c4; }
.kb-search-results .kb-hit-title { display: block; font-size: 0.84rem; line-height: 1.3; }
.kb-search-results .kb-hit-meta { display: block; font-size: 0.72rem; color: var(--site-text-muted, #66605a); }

/* ---------- 日历 ---------- */
.kb-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.kb-cal-month { font-weight: 700; color: var(--site-text, #2b2620); }
.kb-cal-nav { display: flex; gap: 4px; }
.kb-cal-nav button {
  border: 1px solid var(--site-line, #efe0d6);
  background: #fffdfb;
  border-radius: 7px;
  width: 24px; height: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--site-text-muted, #66605a);
}
.kb-cal-nav button:hover { border-color: #e4593a; color: #a04630; }
.kb-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.kb-cal-dow { font-size: 0.68rem; color: var(--site-text-muted, #66605a); padding: 2px 0; }
.kb-cal-cell {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  aspect-ratio: 1 / 1;
  border-radius: 7px;
  font-size: 0.74rem;
  color: var(--site-text-muted, #66605a);
  text-decoration: none;
}
.kb-cal-cell.is-empty { visibility: hidden; }
.kb-cal-cell.has-items { background: #fff1e9; color: #a04630; font-weight: 700; }
.kb-cal-cell.has-items:hover { background: #ffe2d6; }
.kb-cal-cell.is-today { outline: 1.5px solid #e4593a; }
.kb-cal-dot { width: 4px; height: 4px; border-radius: 50%; background: #e4593a; position: absolute; bottom: 4px; }

/* ---------- 标签树 ---------- */
.kb-tagtree { display: flex; flex-direction: column; gap: 1px; }
.kb-tagtree-head { display: flex; align-items: center; gap: 4px; }
.kb-tagtree-domain { flex: 1 1 auto; display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; text-decoration: none; color: var(--site-text, #2b2620); }
.kb-tagtree-domain:hover { background: #fff1e9; }
.kb-tagtree-toggle {
  flex: 0 0 16px;
  width: 16px; height: 16px;
  border: none; background: none; cursor: pointer;
  color: var(--site-text-muted, #66605a);
  padding: 0; display: inline-flex; align-items: center; justify-content: center;
}
.kb-tagtree-toggle::before {
  content: "";
  width: 0; height: 0;
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent currentColor;
  transition: transform 0.15s ease;
}
.kb-tagtree-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
span.kb-tagtree-toggle { cursor: default; }
.kb-tagtree-children { display: none; margin: 2px 0 6px 22px; flex-direction: column; gap: 1px; }
.kb-tagtree-children.is-open { display: flex; }
.kb-tagtree-child { display: flex; padding: 4px 8px; border-radius: 7px; text-decoration: none; color: var(--site-text-muted, #66605a); font-size: 0.82rem; }
.kb-tagtree-child:hover { background: #fff1e9; color: #a04630; }
.kb-tagtree-child.is-active { color: #a04630; font-weight: 700; background: #fff1e9; }

/* ---------- 内容区 ---------- */
.kb-main { min-width: 0; }
.kb-hero { background: linear-gradient(135deg, #fff6ee 0%, #fff1e9 100%); border: 1px solid var(--site-line, #efe0d6); border-radius: 16px; padding: 22px 24px; margin-bottom: 22px; }
.kb-hero h1 { font-size: 1.6rem; font-weight: 800; color: var(--site-text, #2b2620); line-height: 1.25; }
.kb-hero p { margin-top: 8px; color: var(--site-text-muted, #66605a); font-size: 0.92rem; line-height: 1.6; }
.kb-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 16px; }
.kb-kpi-item { background: #fff; border: 1px solid var(--site-line, #efe0d6); border-radius: 11px; padding: 10px 12px; }
.kb-kpi-value { font-size: 1.22rem; font-weight: 800; color: #a04630; font-variant-numeric: tabular-nums; }
.kb-kpi-label { font-size: 0.74rem; color: var(--site-text-muted, #66605a); }

.kb-section { margin-bottom: 26px; }
.kb-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.kb-section-title { font-size: 1.06rem; font-weight: 800; color: var(--site-text, #2b2620); }
.kb-section-more { font-size: 0.8rem; color: #a04630; text-decoration: none; font-weight: 700; }
.kb-section-more:hover { text-decoration: underline; }

.kb-domains { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.kb-domain-card { display: block; background: #fff; border: 1px solid var(--site-line, #efe0d6); border-radius: 12px; padding: 12px 14px; text-decoration: none; }
.kb-domain-card:hover { border-color: #ffd3c4; box-shadow: 0 4px 14px rgba(228, 89, 58, 0.08); }
.kb-domain-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kb-domain-name { font-weight: 700; color: var(--site-text, #2b2620); font-size: 0.95rem; }
.kb-domain-count { font-size: 0.78rem; color: #a04630; background: #ffe2d6; border-radius: 999px; padding: 1px 9px; font-variant-numeric: tabular-nums; }
.kb-domain-desc { margin-top: 6px; font-size: 0.78rem; color: var(--site-text-muted, #66605a); line-height: 1.5; }

.kb-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; background: #fff; border: 1px solid var(--site-line, #efe0d6); border-radius: 12px; overflow: hidden; }
.kb-table th, .kb-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #f6ece5; vertical-align: top; }
.kb-table th { background: #fff8f4; font-size: 0.75rem; letter-spacing: 0.04em; color: var(--site-text-muted, #66605a); text-transform: uppercase; }
.kb-table tr:last-child td { border-bottom: none; }
.kb-table a { color: var(--site-text, #2b2620); text-decoration: none; }
.kb-table a:hover { color: #a04630; text-decoration: underline; }
.kb-table .kb-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--site-text-muted, #66605a); white-space: nowrap; }

.kb-list { display: flex; flex-direction: column; }
.kb-item { padding: 12px 0; border-bottom: 1px solid #f6ece5; }
.kb-item:last-child { border-bottom: none; }
.kb-item-title { font-size: 0.98rem; font-weight: 700; line-height: 1.4; }
.kb-item-title a { color: var(--site-text, #2b2620); text-decoration: none; }
.kb-item-title a:hover { color: #a04630; text-decoration: underline; }
.kb-item-digest { margin-top: 4px; font-size: 0.85rem; color: var(--site-text-muted, #66605a); line-height: 1.55; }
.kb-item-meta { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 0.74rem; color: var(--site-text-muted, #66605a); }
.kb-chip { display: inline-flex; align-items: center; gap: 4px; background: #fff1e9; color: #a04630; border-radius: 999px; padding: 1px 8px; font-weight: 700; text-decoration: none; }
.kb-chip:hover { background: #ffe2d6; }
.kb-chip--muted { background: #f4f1ee; color: #66605a; }

.kb-pager { display: flex; align-items: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.kb-btn { border: 1px solid var(--site-line, #efe0d6); background: #fff; color: var(--site-text, #2b2620); border-radius: 9px; padding: 7px 14px; font-size: 0.85rem; font-weight: 700; cursor: pointer; }
.kb-btn:hover:not(:disabled) { border-color: #e4593a; color: #a04630; }
.kb-btn:disabled { opacity: 0.45; cursor: default; }
.kb-pager-info { font-size: 0.8rem; color: var(--site-text-muted, #66605a); }

.kb-empty { padding: 24px; text-align: center; color: var(--site-text-muted, #66605a); font-size: 0.88rem; background: #fff; border: 1px dashed var(--site-line, #efe0d6); border-radius: 12px; }

.kb-archive-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.kb-archive-chips a { font-size: 0.78rem; color: #66605a; background: #f7f3f0; border-radius: 999px; padding: 3px 10px; text-decoration: none; }
.kb-archive-chips a:hover { background: #ffe2d6; color: #a04630; }

.kb-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.kb-links-group { background: #fff; border: 1px solid var(--site-line, #efe0d6); border-radius: 12px; padding: 12px 14px; }
.kb-links-title { font-size: 0.8rem; font-weight: 700; color: var(--site-text, #2b2620); margin-bottom: 8px; }

@media (max-width: 640px) {
  .kb-domains { grid-template-columns: minmax(0, 1fr); }
  .kb-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kb-hero { padding: 18px 16px; }
  .kb-table th, .kb-table td { padding: 7px 8px; font-size: 0.82rem; }
  /* 首页标签透视表的「领域」列在窄屏冗余（标签名已带领域前缀），隐藏后只留标签+篇数 */
  .kb-table--pivot th:nth-child(2), .kb-table--pivot td:nth-child(2) { display: none; }
}

.kb-sidebar-toggle { display: none; }

@media (max-width: 900px) {
  .kb-root { grid-template-columns: minmax(0, 1fr); padding: 16px 14px 48px; }
  .kb-sidebar { position: static; max-height: none; order: 2; }
  .kb-sidebar-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    margin-bottom: 12px; border: 1px solid var(--site-line, #efe0d6); background: #fff;
    border-radius: 9px; padding: 8px 12px; font-size: 0.85rem; font-weight: 700; cursor: pointer; color: var(--site-text, #2b2620);
  }
  .kb-root.is-sidebar-hidden .kb-sidebar { display: none; }
  .kb-hero h1 { font-size: 1.32rem; }
}
