/* =========================================================
   CBlog V3 · 前台样式（独立文件，不与后台样式混合）
   ========================================================= */

/* ---------- 滚动条占位：始终显示滚动条，防止页面切换时内容宽度跳动 ---------- */
html { overflow-y: scroll; }

/* ---------- 主题变量 ---------- */
:root {
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --accent: #0ea5e9;
  --maxw: 1100px;
  --header-h: 64px;

  --bg: #f6f7fb;
  --bg-elevated: #ffffff;
  --bg-subtle: #eef0f6;
  --text: #1f2430;
  --text-muted: #6b7280;
  --text-faint: #9aa1ad;
  --border: #e6e8ef;
  --card-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --radius: .7rem;
}
[data-theme="dark"] {
  --bg: #0f1115;
  --bg-elevated: #171a20;
  --bg-subtle: #1c2027;
  --text: #e6e8eb;
  --text-muted: #9aa1ad;
  --text-faint: #6b7280;
  --border: #262b33;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.6; font-size: 15px;
}
a { color: inherit; }
.container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
img { max-width: 100%; }

/* ---------- 顶部导航 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100; height: var(--header-h);
  background: var(--bg-elevated); border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(180%) blur(8px);
}
.site-header .container { display: flex; align-items: center; gap: 16px; height: 100%; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-weight: 800; background: linear-gradient(135deg, var(--primary), var(--accent));
}
.main-nav { display: flex; gap: 4px; }
.main-nav a {
  padding: 8px 14px; border-radius: 9px; color: var(--text-muted);
  text-decoration: none; font-weight: 500; transition: .15s;
}
.main-nav a:hover, .main-nav a.active { background: var(--bg-subtle); color: var(--text); }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.search-box {
  display: flex; align-items: center; gap: 8px; background: var(--bg-subtle);
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 14px; width: 220px;
}
.search-box input { border: 0; background: transparent; outline: none; color: var(--text); width: 100%; font-size: 14px; }
.search-box svg { flex: none; color: var(--text-faint); }
.admin-entry {
  font-size: 14px; font-weight: 600; color: #fff; background: var(--primary);
  padding: 8px 14px; border-radius: 10px; text-decoration: none; white-space: nowrap; transition: filter .18s;
}
.admin-entry:hover { filter: brightness(1.08); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-subtle); color: var(--text-muted); cursor: pointer;
  display: grid; place-items: center; transition: .15s;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.hamburger { display: none; }

/* ---------- 两栏布局 ---------- */
.layout {
  display: grid; grid-template-columns: 1fr 320px; gap: 32px;
  max-width: var(--maxw); margin: 30px auto; padding: 0 20px; align-items: start;
}
.main-col { min-width: 0; }
.sidebar { display: flex; flex-direction: column; gap: 22px; position: sticky; top: calc(var(--header-h) + 20px); }

/* ---------- 区块标题 ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-head h2, .widget h3 { font-size: 1.15rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 10px; }
.bar { width: 4px; height: 18px; border-radius: 4px; background: linear-gradient(var(--primary), var(--accent)); }

/* ---------- 文章卡片 ---------- */
.card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--card-shadow); }
.post-card { overflow: hidden; margin-bottom: 22px; }
.post-card .cover { height: 180px; position: relative; }
.badge-top, .badge-private { position: absolute; top: 12px; left: 12px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; color: #fff; }
.badge-top { background: #f59e0b; }
.badge-private { background: #6b7280; }
.post-card .post-body { padding: 18px 20px 10px; }
.post-card .post-body h3 { font-size: 1.2rem; margin: 0 0 8px; }
.post-card .post-body h3 a { color: var(--text); text-decoration: none; }
.post-card .post-body h3 a:hover { color: var(--primary); }
.post-summary { color: var(--text-muted); margin: 0 0 12px; }
.post-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.post-tags a { font-size: 12px; color: var(--text-muted); background: var(--bg-subtle); padding: 3px 10px; border-radius: 999px; text-decoration: none; }
.post-tags a:hover { color: #fff; background: var(--primary); }
.post-meta { display: flex; flex-wrap: wrap; gap: 16px; color: var(--text-faint); font-size: .85rem; }
.post-meta i { margin-right: 4px; vertical-align: -0.125em; }

/* ---------- 侧边栏 ---------- */
.widget { padding: 18px 20px; }
.cat-list { list-style: none; margin: 12px 0 0; padding: 0; }
.cat-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.cat-list li:last-child { border-bottom: 0; }
.cat-list a { color: var(--text); text-decoration: none; }
.cat-list a:hover { color: var(--primary); }
.cat-list .count { font-size: .8rem; color: var(--text-faint); background: var(--bg-subtle); padding: 1px 9px; border-radius: 999px; }
.cat-list-lg li { font-size: 1.05rem; padding: 13px 0; }
.cat-list-lg .count { font-size: .85rem; padding: 2px 11px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tag-cloud a { padding: 4px 12px; border-radius: 999px; text-decoration: none; background: var(--bg-subtle); color: var(--text-muted); transition: .15s; }
.tag-cloud a:hover { background: var(--primary); color: #fff; }
.recent-list { list-style: none; margin: 12px 0 0; padding: 0; }
.recent-list li { border-bottom: 1px dashed var(--border); }
.recent-list li:last-child { border-bottom: 0; }
.recent-list a {
  display: inline-block; padding: 6px 0;
  color: #1677ff; text-decoration: none;
  font-weight: 500; font-size: 1rem; line-height: 1.45; transition: color .15s;
}
.recent-list a:hover { color: #0b5ed7; text-decoration: underline; }
[data-theme="dark"] .recent-list a { color: #4c9aff; }
[data-theme="dark"] .recent-list a:hover { color: #8ab8ff; text-decoration: underline; }

/* ---------- 文章详情 ---------- */
.article-head h1 { font-size: 1.9rem; font-weight: 800; margin-bottom: 12px; }
.article-meta { display: flex; flex-wrap: wrap; gap: 18px; color: var(--text-faint); font-size: .9rem; margin-bottom: 22px; }
.article-meta span { display: inline-flex; align-items: center; }
.article-meta i { margin-right: 4px; }
.article-body { line-height: 1.9; font-size: 1.02rem; }
.article-body h2 { margin: 30px 0 12px; font-size: 1.4rem; }
.article-body h3 { margin: 22px 0 10px; font-size: 1.15rem; }
.article-body p { margin: 0 0 16px; }
.article-body blockquote { border-left: 4px solid var(--primary); margin: 18px 0; padding: 4px 18px; color: var(--text-muted); background: var(--bg-subtle); border-radius: 0 8px 8px 0; }
.article-body pre { background: var(--bg-subtle); padding: 16px; border-radius: 10px; overflow: auto; font-size: .9rem; }
.article-body code { background: var(--bg-subtle); padding: 2px 6px; border-radius: 6px; font-size: .9em; }

/* ---------- 富文本正文元素（编辑器产出的表格/列表/图片等） ---------- */
.article-body ul, .article-body ol { margin: 0 0 16px; padding-left: 1.6em; }
.article-body li { margin: 4px 0; }
.article-body img { max-width: 100%; height: auto; border-radius: 8px; }
.article-body a { color: var(--primary); text-decoration: none; }
.article-body a:hover { text-decoration: underline; }
.article-body hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

/* 表格：编辑器会写入固定像素宽度（如 1140px），前台必须收敛到容器宽度，否则撑破布局 */
.article-body table {
  width: 100% !important;
  max-width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: .95rem;
}
.article-body table colgroup,
.article-body table col { width: auto !important; }
.article-body th, .article-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}
.article-body th { background: var(--bg-subtle); font-weight: 600; }
/* 单元格内的段落不再叠加下边距，避免表格被撑高 */
.article-body th p, .article-body td p { margin: 0; }

/* ---------- 代码块 ---------- */
/* 代码块样式统一由 tui-editor.css 的 .rich-text 规则提供（与编辑器保持一致），
   这里不再单独定义，避免两边样式互相覆盖。 */
.toc { position: sticky; top: calc(var(--header-h) + 20px); }
.toc a { color: var(--text-muted); text-decoration: none; font-size: .9rem; display: block; padding: 4px 0; }
.toc a:hover, .toc a.active { color: var(--primary); }
.toc a.sub { padding-left: 14px; font-size: .85rem; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-subtle); color: var(--text); cursor: pointer; text-decoration: none; font-size: 14px; font-weight: 500; transition: .15s; }
.btn:hover { filter: brightness(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-outline { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* 评论 */
.comment { display: flex; gap: 14px; margin-bottom: 20px; }
.comment .avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.comment .c-body { flex: 1; }
.comment .c-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.comment .c-name { font-weight: 600; }
.comment .c-time { font-size: .8rem; color: var(--text-faint); }
.comment .c-text { color: var(--text-muted); margin: 4px 0 8px; }
.comment .c-actions a { font-size: .85rem; color: var(--text-faint); text-decoration: none; margin-right: 14px; }
.comment .c-actions a:hover { color: var(--primary); }
.comment .replies { margin-top: 18px; padding-left: 18px; border-left: 2px solid var(--border); }
.comment-form textarea { width: 100%; min-height: 90px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); resize: vertical; outline: none; font-family: inherit; }
.comment-form .comment-fields { display: flex; gap: 10px; margin-bottom: 10px; }
.comment-form .comment-fields input { flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); outline: none; font-size: 14px; transition: border-color .15s; }
.comment-form .comment-fields input:focus { border-color: var(--primary); }

/* 点赞按钮 */
.btn-like { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-muted); cursor: pointer; font-size: 14px; transition: .2s; }
.btn-like:hover { border-color: var(--primary); color: var(--primary); }
.btn-like.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-like.active svg { fill: #fff; }
.btn-like .like-count { font-weight: 600; }

/* 列表 / 相关 */
.list-group { list-style: none; margin: 0; padding: 0; }
.list-group li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-group li:last-child { border-bottom: 0; }
.list-group a { color: var(--primary); text-decoration: none; }

/* 分页 */
.pagination { display: flex; gap: 8px; justify-content: center; list-style: none; padding: 0; margin: 24px 0 0; }
.pagination a { min-width: 38px; height: 38px; display: grid; place-items: center; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text-muted); text-decoration: none; }
.pagination a:hover { color: var(--primary); border-color: var(--primary); }
.pagination a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination a.disabled { opacity: .5; pointer-events: none; }

/* 面包屑 */
.breadcrumb { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 16px; color: var(--text-faint); font-size: .9rem; }
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb .active { color: var(--text); }

/* ---------- 归档时间轴 ---------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline .year { font-size: 1.2rem; font-weight: 700; margin: 22px 0 12px; position: relative; }
.timeline .year::before { content: ""; position: absolute; left: -23px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }
.timeline .item { display: flex; gap: 12px; padding: 6px 0; color: var(--text-muted); }
.timeline .item .date { color: var(--text-faint); width: 60px; flex: none; }

/* 标签云页 */
.tagcloud-page { display: flex; flex-wrap: wrap; gap: 14px; align-items: baseline; padding: 30px; }
.tagcloud-page a { color: var(--primary); text-decoration: none; }
.tagcloud-page a:hover { text-decoration: underline; }

/* 友链 */
.links-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.link-card { display: flex; gap: 14px; align-items: center; padding: 18px; text-decoration: none; color: var(--text); }
.link-card .lc-logo { width: 52px; height: 52px; border-radius: 12px; flex: none; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.3rem; }
.link-card .lc-name { font-weight: 600; }
.link-card .lc-desc { font-size: .85rem; color: var(--text-muted); }
.alert { padding: 14px 18px; border-radius: 10px; background: var(--bg-subtle); color: var(--text-muted); display: flex; gap: 10px; align-items: center; }

/* 回到顶部 */
.to-top { position: fixed; right: 24px; bottom: 24px; z-index: 90; width: 44px; height: 44px; border-radius: 12px; display: none; place-items: center; box-shadow: var(--card-shadow); border: 0; background: var(--primary); color: #fff; cursor: pointer; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translate(-50%, 20px);
  background: rgba(15, 23, 42, .92); color: #fff; padding: 10px 22px;
  border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18);
  font-size: .9rem; opacity: 0; visibility: hidden; transition: all .25s ease; z-index: 300; pointer-events: none;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.toast.toast-success { background: rgba(34,197,94,.95); }
.toast.toast-error { background: rgba(239,68,68,.95); }

/* ---------- 页脚 ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-elevated); padding: 22px 0; margin-top: 40px; color: var(--text-muted); font-size: .9rem; }
.site-footer .container { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.site-footer .faint { color: var(--text-faint); }

/* ---------- 响应式（仅前台相关） ---------- */
@media (max-width: 992px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}
@media (max-width: 768px) {
  .search-box { width: 150px; }
  .links-grid { grid-template-columns: 1fr; }
  .post-card .cover { height: 160px; }
}
@media (max-width: 480px) {
  .search-box { display: none; }
  .main-nav { display: none; position: absolute; top: var(--header-h); left: 0; right: 0; flex-direction: column; background: var(--bg-elevated); border-bottom: 1px solid var(--border); padding: 10px; }
  .main-nav.open { display: flex; }
  .hamburger { display: grid; }
}
