.rpa-widget {
    margin: 30px 0;
}
.rpa-position-top,
.rpa-position-bottom {
    clear: both;
}

/* Left/Right positions: a flex layout with an explicit `order`, so the
   article column can be forced first on mobile regardless of which
   side the widget is on desktop — this is not possible with floats,
   which is why this replaced the old float-based approach. */
.rpa-cq {
    container-type: inline-size;
}
.rpa-flex-wrap {
    display: flex;
    align-items: flex-start;
    gap: 28px;
}
.rpa-flex-wrap .rpa-main-col {
    flex: 1 1 0%;
    min-width: 0; /* prevents flex children from overflowing on long words/images */
}
.rpa-flex-wrap .rpa-side-col {
    flex: 0 0 auto;
    /* Never take more than 38% of the available row, even before the
       stacking breakpoint below kicks in — protects the article column
       from being crushed on content areas narrower than expected. */
    width: min( var(--rpa-side-width, 300px), 38% );
}
/* Inside the side column, the widget shouldn't add its own extra top
   margin — the flex `gap` above already provides spacing. This is what
   was causing the empty space above the Related Articles box. */
.rpa-side-col .rpa-widget {
    margin: 0;
}

.rpa-flex-left .rpa-side-col  { order: -1; }
.rpa-flex-right .rpa-side-col { order: 2; }

.rpa-section {
    margin-bottom: 26px;
    background: #fafafa;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 16px;
}
.rpa-section-title {
    margin: 0 0 12px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #333;
}

.rpa-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.rpa-item + .rpa-item {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eaeaea;
}
.rpa-item-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}
.rpa-item-thumb {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    border-radius: 6px;
    background-color: #ddd;
    background-size: cover;
    background-position: center;
}
.rpa-no-thumbs .rpa-item-link {
    align-items: flex-start;
}
.rpa-item-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.rpa-item-title {
    font-size: 0.92rem;
    font-weight: 600;
    line-height: 1.3;
}
.rpa-item-link:hover .rpa-item-title {
    text-decoration: underline;
}
.rpa-item-views {
    font-size: 0.78rem;
    color: #777;
}

/* Bottom/top positions look best as a wider grid instead of a narrow list. */
.rpa-position-bottom .rpa-list,
.rpa-position-top .rpa-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.rpa-position-bottom .rpa-item + .rpa-item,
.rpa-position-top .rpa-item + .rpa-item {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}
.rpa-position-bottom .rpa-item-link,
.rpa-position-top .rpa-item-link {
    flex-direction: column;
    align-items: flex-start;
}
.rpa-position-bottom .rpa-item-thumb,
.rpa-position-top .rpa-item-thumb {
    width: 100%;
    height: 120px;
    flex-basis: auto;
}

/* THE key fix: this reacts to the actual width of the column the
   plugin is rendering inside (via .rpa-cq's container-type above), not
   the viewport. A theme can have a narrow article column even on a
   wide desktop screen — a normal @media query can't see that, but a
   container query can. Below this width, stack to full-width instead
   of attempting a cramped two-column split. */
@container (max-width: 650px) {
    .rpa-flex-wrap {
        flex-direction: column;
        gap: 20px;
    }
    .rpa-flex-wrap .rpa-main-col {
        order: 1 !important;
        width: 100%;
    }
    .rpa-flex-wrap .rpa-side-col {
        order: 2 !important;
        width: 100% !important;
        flex-basis: auto !important;
    }
}

/* Fallback for browsers without container query support (Safari <16,
   older Chrome/Firefox): still stacks based on viewport width, same
   behavior as before. Container query support is now the vast
   majority of traffic, so this is a safety net, not the primary fix. */
@media (max-width: 782px) {
    .rpa-flex-wrap {
        flex-direction: column;
        gap: 20px;
    }
    .rpa-flex-wrap .rpa-main-col {
        order: 1 !important;
        width: 100%;
    }
    .rpa-flex-wrap .rpa-side-col {
        order: 2 !important;
        width: 100% !important;
        flex-basis: auto !important;
    }
}

