/* The «مقالات» section (docs/BLOG_PLAN_FA.md §4), on top of site.css and landing.css (tokens, header,
   footer, buttons, FAQ). Long Persian reading text: a calm measure, generous line height, RTL. */

.blog { --measure: 720px; --head-h: 60px; }

/* ------------------------------------------------ reading progress */

.read-progress { position: fixed; inset-inline: 0; top: calc(var(--head-h) - 2px); z-index: 11; height: 3px; pointer-events: none; }
.read-progress span { display: block; height: 100%; background: var(--accent); transform: scaleX(var(--read, 0)); transform-origin: right; }

/* ------------------------------------------------ head */

.post-main { padding: 14px 0 48px; background: radial-gradient(60% 260px at 50% -60px, var(--glow), transparent 75%), var(--bg); }

.crumbs ol { display: flex; align-items: center; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.crumbs li { display: flex; align-items: center; gap: 2px; min-width: 0; }
.crumbs li:last-child { flex: 1; }
.crumbs li:last-child span { overflow: hidden; text-overflow: ellipsis; }
.crumbs a { padding: 4px 2px; color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumb-sep { flex: none; width: 16px; height: 16px; fill: var(--line-strong); }

.post-head { max-width: var(--measure); margin: 18px 0 0; }
.post-head h1 { margin: 0; font-size: clamp(24px, 6.4vw, 36px); font-weight: 700; line-height: 1.6; text-wrap: balance; }
.post-lede { margin: 10px 0 0; color: var(--muted); font-size: 16px; line-height: 1.95; }
.post-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; margin-top: 16px; color: var(--muted); font-size: 13.5px; }
.meta-by { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; }
.meta-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.meta-item .ic { flex: none; width: 17px; height: 17px; fill: var(--muted); }
.avatar { display: inline-grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: 14px; font-weight: 700; line-height: 1; }
.avatar-lg { width: 52px; height: 52px; font-size: 22px; }

.post-cover { max-width: var(--measure); margin: 22px 0 0; }
.post-cover img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-2); }

/* ------------------------------------------------ layout: contents beside the text on wide screens */

.post-grid { display: grid; gap: 18px; margin-top: 24px; }
.post-body { min-width: 0; max-width: var(--measure); }

/* ------------------------------------------------ table of contents */

.toc-box { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.toc-box summary { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 14px; font-weight: 700; cursor: pointer; list-style: none; }
.toc-box summary::-webkit-details-marker { display: none; }
.toc-box summary #toc-title { flex: 1; }
.toc-ic { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--accent-soft); }
.toc-ic .ic { width: 18px; height: 18px; fill: var(--accent-ink); }
.toc-box .chev { width: 22px; height: 22px; fill: var(--muted); transition: transform .2s ease; }
.toc-box[open] .chev { transform: rotate(180deg); }
.toc-list { margin: 0; padding: 4px 8px 10px; list-style: none; counter-reset: toc; border-top: 1px dashed var(--line); }
.toc-list li { counter-increment: toc; }
.toc-list a {
    display: flex;
    gap: 10px;
    padding: 8px 8px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 14.5px;
    line-height: 1.7;
    text-decoration: none;
    transition: background .15s ease, color .15s ease;
}
.toc-list a::before { content: counter(toc, persian) "."; flex: none; min-width: 1.4em; color: var(--line-strong); font-weight: 700; }
.toc-list a:hover { background: var(--surface-2); color: var(--text); }
.toc-list a.is-current { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.toc-list a.is-current::before { color: var(--accent-ink); }

/* ------------------------------------------------ the article text */

.post-prose { font-size: 16.5px; line-height: 2.05; overflow-wrap: break-word; }
.post-prose > :first-child { margin-top: 0; }
.post-prose p, .post-prose ul, .post-prose ol { margin: 0 0 1.15em; }
.post-prose h2, .post-faq h2, .related h2 { margin: 1.9em 0 .6em; font-size: clamp(20px, 5vw, 24px); font-weight: 700; line-height: 1.6; text-wrap: balance; }
.post-prose h3 { margin: 1.6em 0 .4em; font-size: 18.5px; font-weight: 700; line-height: 1.7; }
.post-prose h4 { margin: 1.4em 0 .3em; font-size: 16.5px; font-weight: 700; }
.post-prose h2, .post-prose h3, .post-faq h2 { scroll-margin-top: calc(var(--head-h) + 16px); }
.post-prose ul, .post-prose ol { padding-inline-start: 1.5em; }
.post-prose ol { list-style-type: persian; }
.post-prose li { margin: .3em 0; padding-inline-start: .2em; }
.post-prose li::marker { color: var(--accent-ink); font-weight: 700; }
.post-prose a { color: var(--text); font-weight: 600; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 6px; }
.post-prose a:hover { color: var(--accent-ink); }
.post-prose strong { font-weight: 700; }
.post-prose hr { margin: 2em 0; border: 0; border-top: 1px solid var(--line); }
.post-prose code { padding: .1em .4em; border-radius: 6px; background: var(--surface-2); font-size: .9em; direction: ltr; unicode-bidi: isolate; }

.post-prose img { display: block; max-width: 100%; height: auto; border-radius: 14px; }
.post-prose figure { margin: 1.6em 0; }
.post-prose figure img { width: 100%; border: 1px solid var(--line); background: var(--surface-2); }
.post-prose figcaption { margin-top: 8px; color: var(--muted); font-size: 13.5px; line-height: 1.8; text-align: center; }

/* Notes: «> ...» then «{.tip}» or «{.warn}». */
.post-prose blockquote { margin: 1.5em 0; padding: 12px 16px; border-inline-start: 4px solid var(--line-strong); border-radius: 4px 14px 14px 4px; background: var(--surface-2); color: var(--text); }
.post-prose blockquote > :last-child { margin-bottom: 0; }
.post-prose blockquote.tip, .post-prose blockquote.warn { padding: 14px 16px; }
.post-prose blockquote.tip { border-color: var(--accent); background: var(--accent-soft); }
.post-prose blockquote.warn { border-color: #D9472B; background: rgba(217, 71, 43, .08); }
.post-prose blockquote.tip::before, .post-prose blockquote.warn::before { display: block; margin-bottom: 2px; font-size: 14px; font-weight: 700; }
.post-prose blockquote.tip::before { content: "نکته"; color: var(--accent-ink); }
.post-prose blockquote.warn::before { content: "دقت کنید"; color: #B5361D; }

/* Tables scroll inside their own box, never the page. */
.table-wrap { margin: 1.5em 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); scrollbar-width: thin; }
.table-wrap:focus-visible { outline-offset: 3px; }
.post-prose table { width: 100%; border-collapse: collapse; font-size: 14.5px; line-height: 1.8; }
.post-prose th, .post-prose td { padding: 9px 14px; border-bottom: 1px solid var(--line); text-align: start; white-space: nowrap; }
.post-prose th { background: var(--surface-2); font-weight: 700; }
.post-prose tbody tr:last-child td { border-bottom: 0; }
.post-prose tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.post-prose th[align="center"], .post-prose td[align="center"] { text-align: center; }
.post-prose th[align="left"], .post-prose td[align="left"] { text-align: left; }

/* ------------------------------------------------ FAQ (the shared .faq of landing.css) */

.post-faq .faq-answer { padding: 12px 18px 16px; color: var(--muted); line-height: 2; }
.post-faq .faq-answer > :first-child { margin-top: 0; }
.post-faq .faq-answer > :last-child { margin-bottom: 0; }
.post-faq .faq-answer p, .post-faq .faq-answer ul, .post-faq .faq-answer ol { margin: 0 0 .8em; }
.post-faq .faq-answer a { color: var(--text); font-weight: 600; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 5px; }
.post-faq summary h3 { font-size: 15.5px; }

/* ------------------------------------------------ boxes: the app, the tools */

.cta-box {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 12px 14px;
    margin: 2em 0;
    padding: 16px;
    border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line));
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
    box-shadow: var(--shadow);
}
.post-body > .cta-box { margin-top: 2.2em; }
.cta-logo { width: 52px; height: 52px; border-radius: 14px; }
.cta-ic { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: var(--accent); }
.cta-ic .ic { width: 28px; height: 28px; fill: var(--on-accent); }
.cta-txt strong { display: block; font-size: 16.5px; font-weight: 700; line-height: 1.6; }
.cta-txt p { margin: 2px 0 0; color: var(--muted); font-size: 14px; line-height: 1.9; }
.cta-btn { grid-column: 1 / -1; width: 100%; }
.cta-btn .ic { width: 18px; height: 18px; fill: currentColor; }
.post-prose .cta-btn { color: var(--on-accent); text-decoration: none; }

/* ------------------------------------------------ author */

.author { display: flex; align-items: flex-start; gap: 14px; margin-top: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.author-txt { min-width: 0; }
.author-label { display: block; color: var(--muted); font-size: 12.5px; }
.author strong { display: block; font-size: 16px; line-height: 1.6; }
.author p { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.9; }
.author p a { color: var(--text); font-weight: 600; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 5px; }

/* ------------------------------------------------ cards: the list and related articles */

.related { margin-top: 40px; padding-top: 8px; border-top: 1px solid var(--line); }
.related-grid, .list-grid { display: grid; gap: 14px; }
.post-card {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.post-card:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); box-shadow: var(--shadow); transform: translateY(-2px); }
.post-card:focus-within { border-color: var(--accent); }
.card-art { display: grid; place-items: center; aspect-ratio: 1200 / 630; background: linear-gradient(135deg, var(--accent-soft), var(--surface-2)); }
/* Without a picture a phone gets a slim band, not an empty box; in a grid it keeps the row even. */
@media (max-width: 599px) { .card-art.is-empty { aspect-ratio: auto; height: 84px; } }
.card-art img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card-ic { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.card-ic .ic { width: 28px; height: 28px; fill: var(--accent-ink); }
.related .card-art { display: none; }
.card-body { display: flex; flex: 1; flex-direction: column; gap: 6px; padding: 14px 16px 16px; }
.card-title { margin: 0; font-size: 16.5px; font-weight: 700; line-height: 1.7; text-wrap: balance; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a:focus-visible { outline: none; }
/* The whole card is the article's link. */
.card-title a::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.post-card:has(a:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.post-card p { display: -webkit-box; margin: 0; overflow: hidden; color: var(--muted); font-size: 14px; line-height: 1.9; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; }
.card-meta { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; color: var(--muted); font-size: 12.5px; white-space: nowrap; }

/* ------------------------------------------------ the list */

.list-head { max-width: var(--measure); margin: 18px 0 22px; }
.list-head h1 { margin: 0; font-size: clamp(26px, 7vw, 36px); font-weight: 700; line-height: 1.5; }
.pager { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
.pager ol { display: flex; gap: 6px; margin: 0; padding: 0; list-style: none; }
.pager a { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font-weight: 600; text-decoration: none; }
.pager a:hover { border-color: var(--line-strong); }
.pager a[aria-current="page"] { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.pager .ic { width: 18px; height: 18px; fill: currentColor; }
.list-grid + .cta-box, .pager + .cta-box { margin-top: 36px; }

/* ------------------------------------------------ wider screens */

@media (min-width: 600px) {
    .cta-box { grid-template-columns: auto minmax(0, 1fr) auto; padding: 18px 20px; }
    .cta-btn { grid-column: auto; width: auto; }
    .related-grid, .list-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
    .post-main { padding-top: 22px; }
    .post-prose { font-size: 17px; }
    .related-grid, .list-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    /* The newest article leads the first page: picture beside the text, across the grid. */
    .post-card.is-featured { grid-column: 1 / -1; flex-direction: row; }
    .is-featured .card-art { flex: 0 0 55%; aspect-ratio: auto; min-height: 280px; }
    .is-featured .card-body { justify-content: center; gap: 10px; padding: 28px 32px; }
    .is-featured .card-title { font-size: 24px; line-height: 1.6; }
    .is-featured p { font-size: 15.5px; -webkit-line-clamp: 3; line-clamp: 3; }
    .is-featured .card-meta { margin-top: 6px; font-size: 13.5px; }
}

@media (min-width: 1024px) {
    .post-grid { grid-template-columns: minmax(0, var(--measure)) 264px; justify-content: space-between; gap: 48px; }
    .toc { grid-column: 2; grid-row: 1; }
    .post-body { grid-column: 1; grid-row: 1; }
    .toc-box { position: sticky; top: calc(var(--head-h) + 20px); max-height: calc(100vh - var(--head-h) - 40px); overflow-y: auto; scrollbar-width: thin; }
    /* Always open beside the text (blog.js opens it); the summary is only a title here. */
    .toc-box summary { min-height: 48px; cursor: default; pointer-events: none; }
    .toc-box .chev { display: none; }
    .toc-list a { font-size: 14px; padding-block: 6px; }
}

@media (prefers-reduced-motion: reduce) {
    .post-card, .toc-list a, .toc-box .chev { transition: none; }
    .post-card:hover { transform: none; }
}

@media print {
    .lp-head, .lp-foot, .skip, .read-progress, .toc, .cta-box, .related, .crumbs, .pager { display: none !important; }
    .post-main { padding: 0; background: none; }
    .post-prose { font-size: 12pt; }
    .post-faq details { border: 0; }
    .post-faq details > * { display: block; }
}
