/* GossHub 文章详情页样式 */

/* ========== 阅读进度条 ========== */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-light), #818CF8);
    z-index: 9999;
    transition: width 0.1s linear;
    border-radius: 0 2px 2px 0;
}

/* ========== 导航栏 ========== */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
[data-theme="dark"] .navbar {
    background: rgba(11,17,32,0.95);
    backdrop-filter: blur(12px);
    border-bottom-color: rgba(96,165,250,0.1);
}

.navbar-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--gutter);
    display: flex;
    align-items: center;
    height: 56px;
    position: relative;
}

.navbar-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 8px;
    transition: all 0.2s;
    flex-shrink: 0;
    background: var(--bg);
}

.navbar-back:hover {
    color: var(--primary-light);
    background: var(--primary-lighter);
}

.navbar-back i { font-size: 13px; }

/* #3 Logo 公共化 — 文章页返回按钮内的 Logo */
.navbar-back-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.navbar-back-logo svg {
    width: 28px;
    height: 28px;
    border-radius: 7px;
}

.navbar-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    padding: 0 12px;
}

/* ========== 分享按钮组 ========== */
.share-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: var(--white);
    text-decoration: none;
}

.share-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}

.share-btn:active { transform: translateY(0); }

.share-btn-wechat { background: var(--wechat); }
.share-btn-wechat:hover { background: #06AD56; }
.share-btn-weibo { background: #E6162D; }
.share-btn-weibo:hover { background: #CF1428; }
.share-btn-qq { background: #12B7F5; }
.share-btn-qq:hover { background: #0EA1D9; }

.share-btn-copy {
    background: var(--primary-light);
    width: auto;
    padding: 0 10px;
    gap: 5px;
    font-size: 12px;
    font-weight: 500;
}
.share-btn-copy:hover { background: var(--primary); }
.share-btn-copy.copied { background: var(--success); }

/* 分享弹窗 - 微信二维码 */
.wechat-modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.wechat-modal-overlay.active { display: flex; }
.wechat-modal {
    background: var(--white);
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    position: relative;
}
[data-theme="dark"] .wechat-modal {
    background: #1A2332;
    border: 1px solid rgba(96,165,250,0.12);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.wechat-modal h3 { font-size: 16px; margin-bottom: 6px; color: var(--wechat); }
.wechat-modal p { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }
.wechat-qr-container {
    width: 200px; height: 200px;
    margin: 0 auto 16px;
    background: var(--white);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    border: 1px solid var(--border);
    overflow: hidden;
}
.wechat-qr-container canvas {
    display: none !important;
}
.wechat-qr-container img {
    display: block !important;
    max-width: 180px !important;
    max-height: 180px !important;
}
.wechat-modal .close-btn {
    position: absolute; top: 12px; right: 16px;
    background: none; border: none; font-size: 20px;
    color: var(--text-secondary); cursor: pointer; padding: 4px;
}
.wechat-modal .close-btn:hover { color: var(--text); }
.wechat-link-box {
    margin-top: 12px; padding: 10px 12px;
    background: var(--bg); border-radius: 8px;
    font-size: 12px; color: var(--text-secondary);
    word-break: break-all;
    display: flex; align-items: center; gap: 8px;
}
.wechat-link-box span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.wechat-link-box button {
    flex-shrink: 0; background: var(--wechat); color: var(--white); border: none;
    padding: 4px 12px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.wechat-link-box button:hover { background: #06AD56; }

/* ========== 文章头部 ========== */
.article-header {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 32px 0;
}
[data-theme="dark"] .article-header {
    background: #0E1525;
    border-bottom-color: rgba(96,165,250,0.08);
}

.article-header-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.article-cat {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
}

.article-header h1 {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 12px;
}

.article-desc {
    font-size: 16px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 16px;
}

.article-info {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.article-info span {
    display: flex;
    align-items: center;
    gap: 5px;
}

/* #2 文件类型标签 — 使用CSS变量替代硬编码 */
.cat-label-md { background: color-mix(in srgb, var(--primary) 8%, transparent); color: var(--primary); padding: 2px 8px; border-radius: 4px; font-weight: 600; font-size: 12px; }
.cat-label-html { background: color-mix(in srgb, var(--primary-light) 8%, transparent); color: var(--primary-light); padding: 2px 8px; border-radius: 4px; font-weight: 600; font-size: 12px; }

/* ========== 内容区域 + TOC 布局 ========== */
.content-wrapper {
    max-width: var(--container);
    margin: 0 auto;
    padding: 32px var(--gutter);
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.content-main {
    flex: 1;
    min-width: 0;
}

.content-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
[data-theme="dark"] .content-card {
    border: 1px solid rgba(96,165,250,0.08);
}

.content-body {
    padding: 32px;
}

/* #23 让嵌入的HTML内容自适应 + 懒加载 */
.content-body img {
    max-width: 100%;
    height: auto;
}
.content-body svg {
    max-width: 100%;
    height: auto;
}
.content-body > * {
    max-width: 1196px;
}
.content-body div,
.content-body section,
.content-body article,
.content-body main,
.content-body table {
    max-width: 100%;
}

/* ========== TOC 侧边栏 ========== */
.toc-sidebar {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: 80px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    scrollbar-width: thin;
}

.toc-sidebar::-webkit-scrollbar { width: 4px; }
.toc-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.toc-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
[data-theme="dark"] .toc-card {
    border: 1px solid rgba(96,165,250,0.08);
}

.toc-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toc-list {
    list-style: none;
    font-size: 13px;
    line-height: 1.8;
    padding-left: 0;
    border-left: 2px solid var(--border);
    margin-left: 4px;
}

.toc-list li {
    padding-left: 12px;
    position: relative;
}

.toc-list a {
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.15s;
    padding: 1px 0;
}

.toc-list a:hover { color: var(--primary-light); }

.toc-list li.toc-active > a {
    color: var(--primary-light);
    font-weight: 600;
}

.toc-list li.toc-active::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--primary-light);
    border-radius: 1px;
}

.toc-list .toc-h2 { padding-left: 12px; }
.toc-list .toc-h3 { padding-left: 24px; font-size: 12px; }
.toc-list .toc-h4 { padding-left: 36px; font-size: 12px; }

.toc-empty {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 8px 0;
}

/* ========== 后端生成 TOC 样式 ========== */
.toc-card .toc {
    border-left: 2px solid var(--border);
    margin-left: 4px;
}
.toc-card .toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}
.toc-card .toc > ul {
    font-size: 13px;
    line-height: 1.8;
}
.toc-card .toc li {
    padding-left: 12px;
    position: relative;
}
.toc-card .toc > ul > li { padding-left: 12px; }
.toc-card .toc > ul > li > ul { font-size: 12px; padding-left: 12px; }
.toc-card .toc > ul > li > ul > li > ul { font-size: 12px; padding-left: 12px; }
.toc-card .toc a {
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.15s;
    padding: 1px 0;
}
.toc-card .toc a:hover { color: var(--primary-light); }
.toc-card .toc li.toc-active > a { color: var(--primary-light); font-weight: 600; }
.toc-card .toc li.toc-active::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--primary-light);
    border-radius: 1px;
}

/* ========== #6 移动端 TOC 折叠 ========== */
.toc-mobile-toggle {
    display: none;
    width: 100%;
    padding: 10px 16px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    margin-bottom: 16px;
    transition: all 0.2s;
}
.toc-mobile-toggle i { margin-right: 6px; color: var(--primary-light); }
.toc-mobile-toggle:hover { background: var(--primary-lighter); }
[data-theme="dark"] .toc-mobile-toggle {
    background: rgba(96,165,250,0.06);
    border-color: rgba(96,165,250,0.12);
}
[data-theme="dark"] .toc-mobile-toggle:hover {
    background: rgba(96,165,250,0.12);
}

/* ========== Markdown 渲染样式 ========== */
.content-body.markdown-content {
    font-size: 16px;
    line-height: 1.8;
    color: var(--text);
}

.markdown-content h1 { font-size: 28px; font-weight: 700; margin: 32px 0 16px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.markdown-content h2 { font-size: 24px; font-weight: 700; margin: 28px 0 14px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.markdown-content h3 { font-size: 20px; font-weight: 600; margin: 24px 0 12px; }
.markdown-content h4 { font-size: 18px; font-weight: 600; margin: 20px 0 10px; }
.markdown-content h5 { font-size: 16px; font-weight: 600; margin: 16px 0 8px; }
.markdown-content h6 { font-size: 14px; font-weight: 600; margin: 16px 0 8px; color: var(--text-secondary); }

.markdown-content p { margin: 12px 0; }
.markdown-content a { color: var(--primary-light); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color 0.2s; }
.markdown-content a:hover { border-bottom-color: var(--primary-light); }
.markdown-content strong { font-weight: 700; }
.markdown-content em { font-style: italic; }
.markdown-content ul, .markdown-content ol { margin: 12px 0; padding-left: 28px; }
.markdown-content li { margin: 4px 0; }
.markdown-content li > ul, .markdown-content li > ol { margin: 4px 0; }

.markdown-content blockquote {
    margin: 16px 0;
    padding: 12px 20px;
    border-left: 4px solid var(--primary-light);
    background: var(--bg);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}
.markdown-content blockquote p { margin: 4px 0; }

.markdown-content code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', 'Monaco', monospace;
    font-size: 0.88em;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    color: #e11d48;
}
[data-theme="dark"] .markdown-content code { color: #FB7185; }

.markdown-content pre {
    margin: 16px 0;
    padding: 20px;
    background: #1e293b;
    border-radius: 10px;
    overflow-x: auto;
    position: relative;
}
[data-theme="dark"] .markdown-content pre { background: #0D1526; border: 1px solid rgba(96,165,250,0.08); }

.markdown-content pre code {
    background: none;
    padding: 0;
    color: #e2e8f0;
    font-size: 14px;
    line-height: 1.6;
}

/* 代码块复制按钮 */
.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: #94A3B8;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 2;
}
.code-copy-btn:hover { background: rgba(255,255,255,0.2); color: #e2e8f0; }
.code-copy-btn.copied { color: var(--success); background: rgba(16,185,129,0.15); }

.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
}
.markdown-content thead { background: var(--bg); }
.markdown-content th, .markdown-content td {
    padding: 10px 14px;
    border: 1px solid var(--border);
    text-align: left;
}
.markdown-content th { font-weight: 600; }
.markdown-content hr {
    margin: 24px 0;
    border: none;
    border-top: 2px solid var(--border);
}
.markdown-content img {
    border-radius: 8px;
    margin: 12px 0;
    box-shadow: var(--shadow);
}
.markdown-content .footnote, .markdown-content .footnotes { font-size: 14px; color: var(--text-secondary); }

/* ========== 相关文章 ========== */
.related-section {
    max-width: var(--container);
    margin: 40px auto;
    padding: 0 var(--gutter);
}

.related-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
}

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

.related-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
}
[data-theme="dark"] .related-card {
    border: 1px solid rgba(96,165,250,0.08);
}
[data-theme="dark"] .related-card:hover {
    border-color: rgba(96,165,250,0.2);
}

.related-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.related-card h4 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.4;
}

.related-card p {
    font-size: 12px;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ========== 返回顶部 ========== */
.back-to-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--primary-light);
    color: var(--white);
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    z-index: 999;
}
[data-theme="dark"] .back-to-top {
    background: #2563EB;
    box-shadow: 0 4px 16px rgba(37,99,235,0.4);
}
[data-theme="dark"] .back-to-top:hover {
    background: #3B82F6;
}
.back-to-top.visible {
    opacity: 1;
    transform: translateY(0);
}
.back-to-top:hover {
    background: var(--primary);
    transform: translateY(-2px);
}

/* ========== 移动端自适应 ========== */
@media (max-width: 768px) {
    :root { --gutter: 16px; }
    .article-header { padding: 20px 0; }
    .article-header h1 { font-size: 20px; }
    .article-desc { font-size: 14px; }
    .article-info { flex-wrap: wrap; gap: 10px; font-size: 12px; }

    /* #6 移动端 TOC 折叠 */
    .toc-mobile-toggle { display: block; }
    .content-wrapper {
        padding: 16px var(--gutter);
        flex-direction: column;
    }
    .toc-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        order: -1;
    }
    .toc-sidebar.collapsed .toc-card {
        display: none;
    }

    .toc-card { padding: 12px; }
    .content-body { padding: 16px; }
    .content-body > * { max-width: 100%; }
    .related-section { padding: 0 var(--gutter); }
    .related-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .share-group { gap: 4px; }
    .share-btn { width: 28px; height: 28px; font-size: 12px; }
    .share-btn-copy { padding: 0 7px; font-size: 11px; }
    .navbar-title { display: none; }
}

@media (max-width: 480px) {
    :root { --gutter: 12px; }
    .article-header h1 { font-size: 18px; }
    .content-body { padding: 12px; }
    .related-grid { grid-template-columns: 1fr; }
    .related-card { padding: 12px; }
    .navbar-back { padding: 5px 10px; font-size: 13px; }
    .back-to-top { bottom: 20px; right: 20px; width: 40px; height: 40px; font-size: 16px; }
}
