/**
 * 文章一键排版插件 - 前端样式（安全修复版）
 */

/* 基础排版样式 */
.af-formatted-content {
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

/* 段落样式 */
.af-formatted-content p {
    margin-bottom: 1.5em;
    text-align: justify;
    text-justify: inter-ideograph;
    -webkit-hyphens: auto;
    -ms-hyphens: auto;
    hyphens: auto;
}

.af-formatted-content p:last-child {
    margin-bottom: 0;
}

/* 图片容器 */
.af-formatted-content figure.af-image-wrapper {
    margin: 20px auto;
    text-align: center;
    max-width: 100%;
    display: block;
}

.af-formatted-content figure.af-image-wrapper img {
    max-width: 100%;
    height: auto;
    display: inline-block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
}

.af-formatted-content figure.af-image-wrapper img:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.af-formatted-content figcaption {
    font-size: 0.9em;
    color: #666;
    margin-top: 8px;
    font-style: italic;
    text-align: center;
    line-height: 1.4;
}

/* 标题样式 */
.af-formatted-content h1,
.af-formatted-content h2,
.af-formatted-content h3,
.af-formatted-content h4,
.af-formatted-content h5,
.af-formatted-content h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2em;
    margin-bottom: 0.8em;
    color: inherit;
}

.af-formatted-content h1 { font-size: 2em; }
.af-formatted-content h2 { font-size: 1.75em; }
.af-formatted-content h3 { font-size: 1.5em; }
.af-formatted-content h4 { font-size: 1.25em; }
.af-formatted-content h5 { font-size: 1.1em; }
.af-formatted-content h6 { font-size: 1em; }

/* 链接样式 */
.af-formatted-content a {
    text-decoration: none;
    border-bottom: 1px solid currentColor;
    transition: opacity 0.2s;
    color: inherit;
}

.af-formatted-content a:hover,
.af-formatted-content a:focus {
    opacity: 0.8;
    outline: none;
}

.af-formatted-content a:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* 列表样式 */
.af-formatted-content ul,
.af-formatted-content ol {
    margin-bottom: 1.5em;
    padding-left: 2em;
}

.af-formatted-content li {
    margin-bottom: 0.5em;
}

.af-formatted-content ul ul,
.af-formatted-content ol ol,
.af-formatted-content ul ol,
.af-formatted-content ol ul {
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}

/* 引用样式 */
.af-formatted-content blockquote {
    margin: 2em 0;
    padding: 1em 1.5em;
    border-left: 4px solid currentColor;
    background: rgba(0,0,0,0.03);
    font-style: italic;
    opacity: 0.9;
}

.af-formatted-content blockquote p:last-child {
    margin-bottom: 0;
}

.af-formatted-content blockquote cite {
    display: block;
    margin-top: 1em;
    font-size: 0.9em;
    font-style: normal;
    opacity: 0.7;
}

/* 代码样式 */
.af-formatted-content code {
    background: rgba(0,0,0,0.05);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: Consolas, Monaco, 'Andale Mono', 'DejaVu Sans Mono', monospace;
    font-size: 0.9em;
    word-break: break-word;
}

.af-formatted-content pre {
    background: #f4f4f4;
    padding: 1.5em;
    overflow-x: auto;
    border-radius: 6px;
    margin-bottom: 1.5em;
    max-width: 100%;
}

.af-formatted-content pre code {
    background: none;
    padding: 0;
    font-size: 1em;
}

/* 表格样式 */
.af-formatted-content table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5em;
    max-width: 100%;
    overflow-x: auto;
    display: block;
}

.af-formatted-content th,
.af-formatted-content td {
    padding: 0.75em;
    border: 1px solid #ddd;
    text-align: left;
}

.af-formatted-content th {
    background: #f5f5f5;
    font-weight: 600;
}

.af-formatted-content tr:nth-child(even) {
    background: #fafafa;
}

/* 分隔线 */
.af-formatted-content hr {
    border: none;
    border-top: 2px solid #eee;
    margin: 2em 0;
}

/* 各模板特定优化 */

/* 优雅简约模板 */
.af-template-elegant {
    letter-spacing: 0.02em;
}

.af-template-elegant p {
    text-indent: 2em;
}

.af-template-elegant p:first-of-type {
    text-indent: 0;
}

/* 文艺清新模板 */
.af-template-literature {
    letter-spacing: 0.05em;
}

.af-template-literature p {
    text-indent: 2em;
}

/* 技术文档模板 */
.af-template-tech pre,
.af-template-tech code {
    font-family: 'JetBrains Mono', 'Fira Code', Consolas, Monaco, monospace;
}

.af-template-tech h2 {
    border-bottom: 1px solid #eaecef;
    padding-bottom: 0.3em;
}

/* 温暖治愈模板 */
.af-template-warm {
    letter-spacing: 0.01em;
}

.af-template-warm img {
    filter: saturate(0.9) contrast(0.95);
}

/* 响应式优化 */
@media (max-width: 768px) {
    .af-formatted-content {
        font-size: 16px !important;
        line-height: 1.7 !important;
    }
    
    .af-formatted-content figure.af-image-wrapper {
        margin: 15px -15px;
        width: calc(100% + 30px);
        max-width: none;
    }
    
    .af-formatted-content h1 { font-size: 1.75em; }
    .af-formatted-content h2 { font-size: 1.5em; }
    .af-formatted-content h3 { font-size: 1.25em; }
    
    .af-formatted-content table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* 打印优化 */
@media print {
    .af-formatted-content {
        font-size: 12pt !important;
        line-height: 1.5 !important;
        color: #000 !important;
        background: #fff !important;
    }
    
    .af-formatted-content a {
        text-decoration: underline;
        border-bottom: none;
        color: #000 !important;
    }
    
    .af-formatted-content figure.af-image-wrapper {
        page-break-inside: avoid;
        margin: 15px 0;
    }
    
    .af-formatted-content pre,
    .af-formatted-content blockquote {
        page-break-inside: avoid;
        border-left-width: 2pt;
    }
}

/* 减少动画（无障碍） */
@media (prefers-reduced-motion: reduce) {
    .af-formatted-content * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 暗色模式支持（谨慎使用） */
@media (prefers-color-scheme: dark) {
    .af-formatted-content.af-template-elegant,
    .af-formatted-content.af-template-news,
    .af-formatted-content.af-template-tech,
    .af-formatted-content.af-template-minimal {
        /* 不强制反转颜色，尊重用户主题设置 */
    }
}

/* 安全：防止潜在的XSS样式攻击 */
.af-formatted-content [style*="javascript:"],
.af-formatted-content [style*="expression("] {
    display: none !important;
}