/**
 * استایل بدنهٔ مقالات وبلاگ (محتوای CKEditor / HTML)
 * fa/ar: RTL — en: LTR
 */

/* ---------- متغیرهای محتوای مقاله ---------- */
html[dir="rtl"] .post-content {
    --article-body-max-width: min(100%, 72ch);
    --article-link: var(--accent-color, #1565c0);
    --article-link-hover: var(--link-hover-color, #0d47a1);
    --article-link-visited: #7b1fa2;
    --article-border: #e0e0e0;
    --article-quote-bg: rgba(21, 101, 192, 0.06);
    --article-code-bg: #f5f5f5;
}

html[dir="ltr"] .post-content {
    --article-body-max-width: min(100%, 75ch);
    --article-link: var(--accent-color, #1565c0);
    --article-link-hover: var(--link-hover-color, #0d47a1);
    --article-link-visited: #6a1b9a;
    --article-border: #dee2e6;
    --article-quote-bg: rgba(21, 101, 192, 0.06);
    --article-code-bg: #f8f9fa;
}

/* ---------- جهت و تراز متن ---------- */
html[dir="rtl"] .post-content {
    direction: rtl;
    text-align: justify;
    text-justify: inter-word;
}

html[dir="ltr"] .post-content {
    direction: ltr;
    text-align: left;
}

.post-content {
    font-size: clamp(1rem, 2.8vw, 1.125rem);
    line-height: 1.65;
    color: var(--text-color, #333);
    max-width: var(--article-body-max-width);
    margin-inline: auto;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

/* Site theme: keep article body surfaces/text paired in dark + light */
body.page-dark .post-content {
    --text-color: var(--text, #e8eaee);
    --article-border: rgba(232, 234, 238, 0.18);
    --article-quote-bg: rgba(243, 215, 138, 0.12);
    --article-code-bg: #1c2026;
    --article-link: #f3d78a;
    --article-link-hover: #ffe9a8;
    --article-link-visited: #c4b5fd;
    --dark-gray: var(--muted, #b0b6c0);
    --light-gray: #23262c;
    color: var(--text-color);
}

html.theme-light body.page-dark .post-content {
    --text-color: #333333;
    --article-border: #e0e0e0;
    --article-quote-bg: rgba(21, 101, 192, 0.06);
    --article-code-bg: #f5f5f5;
    --article-link: var(--accent-color, #1565c0);
    --article-link-hover: var(--link-hover-color, #0d47a1);
    --article-link-visited: #7b1fa2;
    --dark-gray: #757575;
    --light-gray: #f5f5f5;
}

body.page-dark .post-content tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.04);
}

body.page-dark .post-content tbody tr:hover {
    background: rgba(243, 215, 138, 0.08);
}

html.theme-light body.page-dark .post-content tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

html.theme-light body.page-dark .post-content tbody tr:hover {
    background: rgba(21, 101, 192, 0.04);
}

/* ---------- تیترهای داخل متن ---------- */
.post-content h1,
.post-content h2,
.post-content h3,
.post-content h4,
.post-content h5,
.post-content h6 {
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-color, #212121);
}

.post-content h1 { font-size: clamp(1.5rem, 4vw, 1.85rem); }
.post-content h2 { font-size: clamp(1.35rem, 3.5vw, 1.6rem); }
.post-content h3 { font-size: clamp(1.2rem, 3vw, 1.35rem); }
.post-content h4 { font-size: clamp(1.1rem, 2.5vw, 1.2rem); }

.post-content p {
    margin-bottom: 0.75rem;
}

.post-content p:last-child {
    margin-bottom: 0;
}

/* ---------- لینک‌ها: زیرخط، تمایز رنگ ---------- */
.post-content a {
    color: var(--article-link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

.post-content a:visited {
    color: var(--article-link-visited);
}

.post-content a:hover,
.post-content a:focus-visible {
    color: var(--article-link-hover);
    text-decoration-thickness: 2px;
}

.post-content a:focus-visible {
    outline: 2px solid var(--article-link);
    outline-offset: 2px;
}

/* لینکِ دور تصویر بدون زیرخط مزاحم */
.post-content a:has(img) {
    text-decoration: none;
    display: inline-block;
    max-width: 100%;
}

.post-content a:has(img):hover,
.post-content a:has(img):focus-visible {
    outline: 2px solid var(--article-link);
    outline-offset: 3px;
    border-radius: 8px;
}

/* لیست‌ها */
.post-content ul,
.post-content ol {
    margin: 1rem 0;
    padding-inline-start: 1.5rem;
}

html[dir="rtl"] .post-content ul,
html[dir="rtl"] .post-content ol {
    padding-inline-start: 1.75rem;
}

.post-content li {
    margin-bottom: 0.5rem;
}

.post-content li > ul,
.post-content li > ol {
    margin-top: 0.5rem;
}

/* ---------- جداول: خوانایی + اسکرول افقی در موبایل ---------- */
.post-content table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: clamp(0.8125rem, 2.2vw, 1rem);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
    border-radius: 8px;
    overflow: hidden;
}

.post-content thead {
    background: var(--light-gray, #f5f5f5);
}

.post-content th,
.post-content td {
    border: 1px solid var(--article-border);
    padding: 0.65rem 0.85rem;
    vertical-align: top;
    text-align: inherit;
}

.post-content th {
    font-weight: 600;
}

.post-content tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

.post-content tbody tr:hover {
    background: rgba(21, 101, 192, 0.04);
}

@media (max-width: 767px) {
    .post-content table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
    }

    .post-content th,
    .post-content td {
        word-break: break-word;
        hyphens: auto;
    }
}

/* ---------- نقل‌قول، کد، پیش‌فرمت ---------- */
.post-content blockquote {
    margin: 1.25rem 0;
    padding: 1rem 1.25rem;
    border-inline-start: 4px solid var(--article-link);
    background: var(--article-quote-bg);
    border-radius: 0 8px 8px 0;
}

html[dir="rtl"] .post-content blockquote {
    border-radius: 8px 0 0 8px;
}

.post-content pre {
    margin: 1rem 0;
    padding: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.9em;
    line-height: 1.5;
    background: var(--article-code-bg);
    border: 1px solid var(--article-border);
    border-radius: 8px;
}

.post-content code {
    font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
    font-size: 0.9em;
    padding: 0.15em 0.4em;
    background: var(--article-code-bg);
    border-radius: 4px;
}

.post-content pre code {
    padding: 0;
    background: transparent;
}

/* ---------- تصویر و فیگور داخل متن ---------- */
.post-content figure {
    margin: 1.5rem auto;
    max-width: 100%;
}

.post-content figure img {
    margin-inline: auto;
    border-radius: 8px;
}

.post-content figcaption {
    margin-top: 0.5rem;
    font-size: 0.875em;
    color: var(--dark-gray, #757575);
    text-align: center;
}

html[dir="rtl"] .post-content figcaption {
    text-align: center;
}

/* ---------- جدا کننده ---------- */
.post-content hr {
    margin: 2rem 0;
    border: none;
    border-top: 1px solid var(--article-border);
}
