/* =========================================================
   BLOG — DETAIL (ARTICLE) PAGE
   ========================================================= */

.blog-page {
    --navy: #0F1B2E;
    --bg: #FFFFFF;
    --bg-soft: #F5F8F9;
    --teal: #1B8392;
    --teal-dark: #14606C;
    --teal-tint: #E5F4F5;
    --ink: #1B2430;
    --muted: #5B6773;
    --line: #E1E8EA;

    font-family: 'Inter', Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

.blog-page h1,
.blog-page h2,
.blog-page h3,
.blog-page h4 {
    font-family: 'Space Grotesk', Arial, Helvetica, sans-serif;
}

.cat-pill {
    display: inline-block;
    padding: 4px 11px;
    border-radius: 999px;
    background: var(--teal-tint);
    color: var(--teal-dark);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}


/* ---------------- BREADCRUMB ---------------- */

.article-breadcrumb {
    max-width: 960px;
    margin: 28px auto 0;
    padding: 0 20px;

    color: var(--muted);
    font-size: 0.86rem;
}

.article-breadcrumb a {
    color: var(--muted);
    text-decoration: none;
}

.article-breadcrumb a:hover {
    color: var(--teal-dark);
    text-decoration: underline;
}

.article-breadcrumb span.sep {
    margin: 0 6px;
    color: #B7C1C7;
}

.article-breadcrumb span.current {
    color: var(--ink);
    font-weight: 600;
}


/* ---------------- ARTICLE HEAD ---------------- */

.article-head {
    max-width: 960px;
    margin: 18px auto 0;
    padding: 0 20px;
    text-align: center;
}

.article-head h1 {
    margin: 12px 0 14px;
    font-size: clamp(1.7rem, 4vw, 2.5rem);
    line-height: 1.2;
    color: var(--navy);
}

.article-byline {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    color: var(--muted);
    font-size: 0.9rem;
}

.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--teal);
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
}


/* ---------------- LAYOUT ---------------- */

.article-layout {
    max-width: 1020px;
    margin: 36px auto 0;
    padding: 0 20px;

    display: grid;
    grid-template-columns: 1fr;
    gap: 40px;
    align-items: start;
}

/* Two-column layout when TOC is populated (JS toggles this class) */
.article-layout.has-toc {
    grid-template-columns: 200px 1fr;
}

/* Explicit placement — no reliance on auto-flow */
.article-layout.has-toc > .article-toc {
    grid-column: 1;
    grid-row: 1;
}

.article-layout.has-toc > .article-content {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
}

.article-layout:not(.has-toc) > .article-content {
    grid-column: 1 / -1;
    grid-row: 1;
    min-width: 0;
}

/* Keep the TOC sticky inside its own column */
.article-layout.has-toc > .article-toc {
    position: sticky;
    top: 84px;
    align-self: start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

.article-toc {
    position: sticky;
    top: 84px;

    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
}

.article-toc h4 {
    margin: 0 0 10px;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.article-toc nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.article-toc nav a {
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--muted);
    font-size: 0.85rem;
    text-decoration: none;
    line-height: 1.4;
}

.article-toc nav a.toc-sub {
    padding-left: 18px;
    font-size: 0.8rem;
}

.article-toc nav a:hover {
    color: var(--teal-dark);
    text-decoration: none;
}

.article-toc nav a.active {
    background: var(--teal-tint);
    color: var(--teal-dark);
    font-weight: 600;
}

.article-content {
    min-width: 0;
}

.article-figure {
    margin: 0 0 28px;
}

.article-figure img {
    width: 100%;
    border-radius: 14px;
    display: block;
}

.article-body {
    font-size: 1.02rem;
    line-height: 1.75;
    color: var(--ink);
}

.article-body h2 {
    margin: 34px 0 14px;
    font-size: 1.4rem;
    color: var(--navy);
    scroll-margin-top: 84px;
}

.article-body h3 {
    margin: 26px 0 12px;
    font-size: 1.15rem;
    color: var(--navy);
    scroll-margin-top: 84px;
}

.article-body p {
    margin: 0 0 16px;
}

.article-body ul,
.article-body ol {
    margin: 0 0 16px;
    padding-left: 22px;
}

.article-body img {
    max-width: 100%;
    border-radius: 10px;
}

.article-body a {
    color: var(--teal-dark);
    font-weight: 600;
}

.article-tags {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--line);

    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}


/* ---------------- RELATED ---------------- */

.related-section {
    max-width: 1020px;
    margin: 56px auto 0;
    padding: 40px 20px 64px;
    border-top: 1px solid var(--line);
}

.related-section h2 {
    margin: 0 0 20px;
    font-size: 1.3rem;
    color: var(--navy);
}

.related-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.blog-card {
    display: flex;
    flex-direction: column;

    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;

    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.blog-card:hover {
    box-shadow: 0 10px 24px rgba(15, 27, 46, 0.1);
    transform: translateY(-2px);
    text-decoration: none;
    color: inherit;
}

.blog-card-media img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}

.blog-card-body {
    padding: 14px 16px 16px;
}

.blog-card-body h3 {
    margin: 8px 0 0;
    font-size: 0.95rem;
    line-height: 1.35;
    color: var(--navy);
}

.no-related {
    grid-column: 1 / -1;
    color: var(--muted);
    text-align: center;
    padding: 20px 0;
}

/* ═══ Article tables ═══════════════════════════════════════════════
   Mirrors the look of CKEditor 5's table styling so published
   articles render tables the same way editors see them in the
   admin.
   ═══════════════════════════════════════════════════════════════════ */

.article-content table,
.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.25rem 0;
    font-size: 0.95rem;
    line-height: 1.5;
    background: #fff;
}

.article-content thead,
.article-body thead {
    background: #f9fafb;
}

.article-content th,
.article-content td,
.article-body th,
.article-body td {
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    text-align: left;
    vertical-align: top;
}

.article-content th,
.article-body th {
    font-weight: 600;
    color: #1f2937;
    background: #f3f4f6;
}

.article-content tbody tr:nth-child(even) td,
.article-body tbody tr:nth-child(even) td {
    background: #fafafa;
}

@media (max-width: 800px) {

    /* Collapse to a single column.
       .article-layout.has-toc must be listed explicitly because
       .article-layout.has-toc has higher specificity than
       .article-layout alone, so the single-column rule here
       would otherwise be ignored on mobile. */
    .article-layout,
    .article-layout.has-toc {
        grid-template-columns: 1fr;
    }

    /* Reset the explicit grid placements applied for the
       two-column desktop layout so the TOC and content
       flow naturally in the collapsed column. */
    .article-layout.has-toc > .article-toc,
    .article-layout.has-toc > .article-content {
        grid-column: auto;
        grid-row: auto;
    }

    /* Sticky positioning doesn't make sense when the TOC
       moves below the content on mobile. */
    .article-layout.has-toc > .article-toc {
        position: static;
        max-height: none;
    }

    .article-toc {
        position: static;
        order: 2;
    }

    /* Force ALL images (however nested) to fit the column */
    .article-content img,
    .article-content figure img,
    .article-content .article-figure img {
        max-width: 100% !important;
        height: auto !important;
        display: block;
    }

    /* Aggressive wrap for FLOWING TEXT (paragraphs, list items,
       headings) so long URLs and unbroken tokens don't overflow.
       Scoped to text flow — tables handled separately below. */
    .article-content p,
    .article-content li,
    .article-content h1,
    .article-content h2,
    .article-content h3,
    .article-content h4,
    .article-content h5,
    .article-content h6,
    .article-content blockquote,
    .article-body p,
    .article-body li,
    .article-body h1,
    .article-body h2,
    .article-body h3,
    .article-body h4,
    .article-body h5,
    .article-body h6,
    .article-body blockquote {
        overflow-wrap: break-word;
        word-wrap: break-word;
        max-width: 100%;
    }

    /* Tables: become horizontally scrollable inside the article.
       Fixed min-width (600px) forces overflow on small screens,
       giving each column enough room to show its content without
       wrapping awkwardly. Users swipe horizontally inside the
       table to see the rest. */
    

    /* Keep table sections in true table layout so widths
       distribute correctly inside the 600px scroll area. */
    

    /* Cells inside the scroll: allow natural wrap at spaces only,
       never break words mid-syllable. */
    .article-content th,
    .article-content td,
    .article-body th,
    .article-body td {
        overflow-wrap: normal;
        word-break: normal;
        white-space: normal;
    }

    /* Code blocks: scrollable, no line wrap */
    .article-content pre,
    .article-content code,
    .article-body pre,
    .article-body code {
        white-space: pre-wrap;
        overflow-wrap: anywhere;
        max-width: 100%;
    }

    /* Inline media fit within their container */
    .article-content video,
    .article-content iframe,
    .article-body video,
    .article-body iframe {
        max-width: 100%;
    }

    .related-grid {
        grid-template-columns: 1fr;
    }
}

/* ═══ First-Paint Overflow Safeguard ═════════════════════════════
   Sometimes CKEditor elements (like wide tables inside figure.table)
   force a horizontal scrollbar on the very first mobile paint before
   the browser recalculates the container width. 
   Clamping the main wrapper prevents this. */
.blog-page {
    max-width: 100vw;
    overflow-x: hidden;
}

@media (max-width: 800px) {
    .article-layout,
    .article-content,
    .article-body,
    figure.table {
        max-width: 100%;
        overflow-x: hidden;
    }
}
