/*
Markdown 内容排版增强
作用范围：.article-content（文章详情页正文）
依赖：article-detail.css（基础排版）
*/

.article-content {
    --md-border: #e5e7eb;
    --md-border-strong: #d0d7de;
    --md-muted: #57606a;
    --md-subtle-bg: #f6f8fa;
    --md-stripe-bg: #fafbfc;
    --md-hover-bg: #f0fdf4;
    --md-head-bg: #f3f4f6;
    --md-accent: #059669;
    --md-mark-bg: #fff3b0;
    --md-radius: 8px;

    overflow-wrap: break-word;
}

/* ===== 首尾元素间距 ===== */
.article-content > :first-child {
    margin-top: 0;
}

.article-content > :last-child {
    margin-bottom: 0;
}

/* ===== 标题 ===== */
.article-content h2 {
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--md-border);
}

.article-content h5 {
    font-size: 17px;
}

.article-content h6 {
    font-size: 15px;
    color: var(--md-muted);
}

.article-content h1 + h2,
.article-content h2 + h3,
.article-content h3 + h4 {
    margin-top: 24px;
}

/* ===== 表格 ===== */
.article-content .md-table-wrap {
    margin: 32px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--md-border-strong);
    border-radius: var(--md-radius);
}

.article-content table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    font-size: 15px;
    line-height: 1.6;
    text-align: left;
}

/* 未被包裹的表格（如编辑器直接输出）也保持边框 */
.article-content > table {
    margin: 32px 0;
    border: 1px solid var(--md-border-strong);
}

.article-content th,
.article-content td {
    padding: 10px 14px;
    border: 1px solid var(--md-border);
    vertical-align: top;
}

/* 包裹容器已有外框，去掉单元格最外侧边框，避免双线 */
.article-content .md-table-wrap tr > :first-child {
    border-left: 0;
}

.article-content .md-table-wrap tr > :last-child {
    border-right: 0;
}

.article-content .md-table-wrap tr:first-child > * {
    border-top: 0;
}

.article-content .md-table-wrap thead + tbody tr:first-child > * {
    border-top: 1px solid var(--md-border);
}

.article-content .md-table-wrap tbody tr:last-child > * {
    border-bottom: 0;
}

.article-content th {
    background: var(--md-head-bg);
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
}

.article-content thead th {
    border-bottom: 2px solid var(--md-border-strong);
}

.article-content tbody tr:nth-child(even) {
    background: var(--md-stripe-bg);
}

.article-content tbody tr:hover {
    background: var(--md-hover-bg);
}

.article-content td:empty::after {
    content: "—";
    color: #c0c4cc;
}

.article-content table p {
    margin: 0;
    text-align: inherit;
}

.article-content table img {
    margin: 0;
    box-shadow: none;
}

/* ===== 分割线 ===== */
.article-content hr {
    height: 1px;
    margin: 48px 0;
    padding: 0;
    border: 0;
    background: var(--md-border);
}

/* ===== 列表 ===== */
.article-content ul {
    list-style: disc;
}

.article-content ol {
    list-style: decimal;
}

.article-content ul ul,
.article-content ol ul {
    list-style: circle;
}

.article-content ul ul ul,
.article-content ol ul ul {
    list-style: square;
}

.article-content ol ol {
    list-style: lower-alpha;
}

.article-content li > ul,
.article-content li > ol {
    margin: 6px 0;
}

.article-content li > p {
    margin: 8px 0;
}

.article-content li::marker {
    color: var(--md-muted);
}

/* 任务列表 - [ ] / - [x] */
.article-content li:has(> input[type="checkbox"]),
.article-content .task-list-item {
    list-style: none;
}

.article-content li > input[type="checkbox"] {
    margin: 0 8px 0 -22px;
    vertical-align: middle;
    accent-color: var(--md-accent);
}

/* ===== 行内元素 ===== */
.article-content strong,
.article-content b {
    font-weight: 700;
    color: #1a1a1a;
}

.article-content del,
.article-content s {
    color: var(--md-muted);
}

.article-content mark {
    padding: 0 2px;
    background: var(--md-mark-bg);
    color: inherit;
    border-radius: 2px;
}

.article-content kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: 'SF Mono', Monaco, Consolas, 'Courier New', monospace;
    font-size: 0.8em;
    line-height: 1.2;
    color: #24292f;
    background: var(--md-subtle-bg);
    border: 1px solid var(--md-border-strong);
    border-bottom-width: 2px;
    border-radius: 4px;
}

.article-content sup,
.article-content sub {
    font-size: 0.75em;
    line-height: 0;
}

.article-content abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
}

/* ===== 引用块 ===== */
.article-content blockquote {
    font-style: normal;
}

.article-content blockquote > :first-child {
    margin-top: 0;
}

.article-content blockquote > :last-child {
    margin-bottom: 0;
}

.article-content blockquote blockquote {
    margin: 16px 0;
}

/* ===== 代码块 ===== */
.article-content pre {
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid var(--md-border);
    white-space: pre;
    tab-size: 4;
}

.article-content pre code {
    display: block;
    font-size: inherit;
    white-space: inherit;
}

/* ===== 图片 / 图注 ===== */
.article-content p > img:only-child {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.article-content figure {
    margin: 32px 0;
    text-align: center;
}

.article-content figure img {
    margin: 0 auto;
}

.article-content figcaption {
    margin-top: 8px;
    font-size: 14px;
    color: var(--md-muted);
}

/* ===== 定义列表 ===== */
.article-content dl {
    margin: 24px 0;
}

.article-content dt {
    font-weight: 600;
    margin-top: 16px;
}

.article-content dd {
    margin: 4px 0 0 24px;
    color: var(--md-muted);
}

/* ===== 折叠块 <details> ===== */
.article-content details {
    margin: 24px 0;
    padding: 12px 16px;
    border: 1px solid var(--md-border);
    border-radius: var(--md-radius);
    background: var(--md-subtle-bg);
}

.article-content summary {
    font-weight: 600;
    cursor: pointer;
}

.article-content details[open] > summary {
    margin-bottom: 12px;
}

/* ===== 脚注 ===== */
.article-content .footnotes {
    margin-top: 48px;
    padding-top: 16px;
    border-top: 1px solid var(--md-border);
    font-size: 14px;
    color: var(--md-muted);
}

.article-content .footnotes hr {
    display: none;
}

.article-content .footnotes p {
    margin: 4px 0;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .article-content table {
        font-size: 14px;
    }

    .article-content th,
    .article-content td {
        padding: 8px 10px;
    }

    .article-content hr {
        margin: 36px 0;
    }

    .article-content pre {
        font-size: 13px;
        padding: 16px;
        border-radius: 6px;
    }
}

/* ===== 深色模式 ===== */
@media (prefers-color-scheme: dark) {
    .article-content {
        --md-border: #30363d;
        --md-border-strong: #3d444d;
        --md-muted: #8b949e;
        --md-subtle-bg: #161b22;
        --md-stripe-bg: #11161d;
        --md-hover-bg: #1c2a24;
        --md-head-bg: #161b22;
        --md-mark-bg: #5c4a00;
    }

    .article-content th,
    .article-content strong,
    .article-content b,
    .article-content pre code,
    .article-content kbd {
        color: #f0f6fc;
    }

    .article-content td:empty::after {
        color: #484f58;
    }
}

/* ===== 打印 ===== */
@media print {
    .article-content .md-table-wrap {
        overflow: visible;
    }

    .article-content tbody tr:nth-child(even),
    .article-content th {
        background: none !important;
    }
}
