/* v1.5.4c PUBLIC CONTENT LAYOUT FIX
   Repairs public article/news layout after portal homepage recovery.
   Prevents article body from being squeezed into the right sidebar.
*/

.public-content-layout,
.article-layout,
.news-layout,
.content-layout,
.page-layout,
.content-with-sidebar,
.article-shell,
.news-shell,
.article-page,
.news-page,
.article-detail,
.news-detail {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) 330px !important;
    gap: 32px !important;
    align-items: start !important;
    width: 100% !important;
}

.public-content-main,
.article-main,
.news-main,
.content-main,
.article-content,
.news-content,
.page-content,
.entry-content,
.article-body,
.news-body {
    min-width: 0 !important;
    width: 100% !important;
    max-width: none !important;
    grid-column: 1 !important;
}

.public-content-sidebar,
.article-sidebar,
.news-sidebar,
.content-sidebar,
.page-sidebar,
.sidebar,
.side-card,
.article-side-card,
.news-side-card {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 360px !important;
    grid-column: 2 !important;
}

/* Common fallback: if the public template uses generic container/card nesting */
.container > .article-card,
.container > .news-card,
.container > .content-card {
    max-width: none !important;
}

/* Ensure long paragraphs use the main column naturally */
.article-content p,
.news-content p,
.article-body p,
.news-body p,
.entry-content p,
.page-content p {
    max-width: 78ch !important;
    line-height: 1.7 !important;
}

/* Prevent floating images/captions from forcing text into tiny columns */
.article-content figure,
.news-content figure,
.article-body figure,
.news-body figure,
.entry-content figure,
.article-content img,
.news-content img,
.article-body img,
.news-body img {
    max-width: 100% !important;
}

/* Clear problematic legacy floats on article/news pages */
.article-content::after,
.news-content::after,
.article-body::after,
.news-body::after,
.entry-content::after {
    content: "";
    display: table;
    clear: both;
}

/* Legacy fix: body text may have been pushed after sidebar if cards were flexed */
.article-layout > .card:first-child,
.news-layout > .card:first-child,
.content-layout > .card:first-child,
.public-content-layout > .card:first-child {
    grid-column: 1 !important;
}

.article-layout > .card:last-child,
.news-layout > .card:last-child,
.content-layout > .card:last-child,
.public-content-layout > .card:last-child {
    grid-column: 2 !important;
}

/* If a page accidentally wraps the body and sidebar in reverse order, keep body wider */
.article-layout .article-hero,
.news-layout .news-hero,
.content-layout .content-hero {
    grid-column: 1 / -1 !important;
}

/* Mobile stacking */
@media(max-width: 980px) {
    .public-content-layout,
    .article-layout,
    .news-layout,
    .content-layout,
    .page-layout,
    .content-with-sidebar,
    .article-shell,
    .news-shell,
    .article-page,
    .news-page,
    .article-detail,
    .news-detail {
        grid-template-columns: 1fr !important;
    }

    .public-content-main,
    .article-main,
    .news-main,
    .content-main,
    .article-content,
    .news-content,
    .page-content,
    .entry-content,
    .article-body,
    .news-body,
    .public-content-sidebar,
    .article-sidebar,
    .news-sidebar,
    .content-sidebar,
    .page-sidebar,
    .sidebar,
    .side-card,
    .article-side-card,
    .news-side-card,
    .article-layout > .card:first-child,
    .news-layout > .card:first-child,
    .content-layout > .card:first-child,
    .public-content-layout > .card:first-child,
    .article-layout > .card:last-child,
    .news-layout > .card:last-child,
    .content-layout > .card:last-child,
    .public-content-layout > .card:last-child {
        grid-column: 1 !important;
        max-width: none !important;
    }
}
