/* Related Posts — Front-end Card Grid + Carousel */

.cc-rp-wrapper {
    margin: 40px 0;
    /* Establish a container so child layout can respond to the block's
       own width rather than the viewport. This makes the grid stack
       correctly when placed inside narrow columns. */
    container-type: inline-size;
    container-name: cc-rp;
}

/* ---- Carousel wrapper ---- */

.cc-rp-carousel {
    position: relative;
}

/* ==================================================================
   Layout: Cards (3-col)
   ================================================================== */

.cc-rp-layout-cards .cc-rp-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.cc-rp-grid.cc-rp-scrollable {
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.cc-rp-grid.cc-rp-scrollable::-webkit-scrollbar {
    display: none;
}

.cc-rp-layout-cards .cc-rp-grid.cc-rp-scrollable {
    grid-template-columns: unset;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - 2 * 20px) / 3);
}

/* ---- Card (full) ---- */

.cc-rp-card {
    position: relative;
    scroll-snap-align: start;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: border-color 0.2s ease;
}
.cc-rp-card:hover {
    border-color: #6b7280;
}

.cc-rp-card-img {
    display: block;
    line-height: 0;
}
.cc-rp-card-img img {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

/* Placeholder when a post has no featured image (theme SVG) */
.cc-rp-card-img--fallback {
    background: #e2e8f0;
}

.cc-rp-card-body {
    padding: 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Title — the <a> inside stretches over the entire card via ::after */
.cc-rp-card-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
    margin: 0 0 8px;
}
.cc-rp-card-title a {
    color: inherit;
    text-decoration: none;
}
.cc-rp-card-title a::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
}
.cc-rp-card:hover .cc-rp-card-title a {
    color: var(--theme-palette-color-1, #2271b1);
}

.cc-rp-card-excerpt {
    font-size: 0.875rem;
    line-height: 1.5;
    color: #555;
    margin: 0 0 12px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}
.cc-rp-card-more {
    display: block;
    text-align: right;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--theme-palette-color-1, #2271b1);
    margin-top: auto;
}

/* ==================================================================
   Layout: Compact (2-col, thumbnail + title side-by-side)
   ================================================================== */

.cc-rp-layout-compact .cc-rp-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: auto;
    gap: 12px;
}

.cc-rp-layout-compact .cc-rp-grid.cc-rp-scrollable {
    grid-template-columns: unset;
    grid-template-rows: repeat(2, auto);
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - 12px) / 2);
}

.cc-rp-card-compact {
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    border-radius: 6px;
    min-height: 85px;
}
.cc-rp-card-compact .cc-rp-card-img {
    flex-shrink: 0;
    width: 90px;
    align-self: stretch;
}
.cc-rp-card-compact .cc-rp-card-img img {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: cover;
    display: block;
}
.cc-rp-card-compact .cc-rp-card-title {
    padding: 8px 12px;
    font-size: 0.875rem;
    line-height: 1.3;
    margin: 0;
    display: flex;
    align-items: center;
}

/* ---- Arrows ---- */

.cc-rp-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    padding: 0;
    opacity: 0;
    transition: opacity 0.25s ease;
    pointer-events: none;
}
.cc-rp-carousel:hover .cc-rp-arrow:not([hidden]) {
    opacity: 1;
    pointer-events: auto;
}
.cc-rp-arrow-left {
    left: -8px;
    background: #fff;
    color: #1d2327;
}
.cc-rp-arrow-left:hover {
    background: #f0f0f1;
}
.cc-rp-arrow-right {
    right: -8px;
    background: #1d2327;
    color: #fff;
}
.cc-rp-arrow-right:hover {
    background: #2c3338;
}

/* ---- Unpublished post cards (private/draft, logged-in only) ---- */

.cc-rp-card-unpublished {
    opacity: 0.55;
    border-style: dashed;
}
.cc-rp-card-unpublished:hover {
    opacity: 0.85;
}
.cc-rp-card-unpublished .cc-rp-card-img {
    opacity: calc(1 / 0.55);
}
.cc-rp-card-unpublished:hover .cc-rp-card-img {
    opacity: calc(1 / 0.85);
}

/* ---- Responsive (container-based, not viewport-based) ----
   Breakpoints are tuned to the block's own width so the layout adapts
   the same way whether the block is in a full-width post body, a narrow
   sidebar column, or on a small phone. */

/* Cards (3-col): once the container can't fit three cards side-by-side,
   one of three things happens:
     - Default: stack to a single column.
     - cc-rp-scrollable (editor opted in): swipe carousel, 1 card + peek.
     - cc-rp-mobile-scrollable (auto safety net for long lists when the
       editor did NOT opt in): same swipe carousel — desktop is unaffected
       because the class only triggers behavior inside this @container. */
@container cc-rp (max-width: 600px) {
    .cc-rp-layout-cards .cc-rp-grid:not(.cc-rp-scrollable):not(.cc-rp-mobile-scrollable) {
        grid-auto-flow: row;
        grid-auto-columns: unset;
        grid-template-columns: 1fr;
        overflow-x: visible;
        scroll-snap-type: none;
    }
    .cc-rp-layout-cards .cc-rp-grid.cc-rp-scrollable,
    .cc-rp-layout-cards .cc-rp-grid.cc-rp-mobile-scrollable {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        grid-template-columns: unset;
        grid-auto-flow: column;
        grid-auto-columns: 85%;
    }
    .cc-rp-layout-cards .cc-rp-grid.cc-rp-scrollable::-webkit-scrollbar,
    .cc-rp-layout-cards .cc-rp-grid.cc-rp-mobile-scrollable::-webkit-scrollbar {
        display: none;
    }
}

/* Compact (2-col): same three-way logic as cards, but the carousel
   "page" is a single column of two stacked cards (mirrors the desktop
   2×2 chunk). */
@container cc-rp (max-width: 480px) {
    .cc-rp-layout-compact .cc-rp-grid:not(.cc-rp-scrollable):not(.cc-rp-mobile-scrollable) {
        grid-auto-flow: row;
        grid-auto-columns: unset;
        grid-template-columns: 1fr;
        grid-template-rows: unset;
        overflow-x: visible;
        scroll-snap-type: none;
    }
    .cc-rp-layout-compact .cc-rp-grid.cc-rp-scrollable,
    .cc-rp-layout-compact .cc-rp-grid.cc-rp-mobile-scrollable {
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        grid-template-columns: unset;
        grid-template-rows: repeat(2, auto);
        grid-auto-flow: column;
        grid-auto-columns: 85%;
    }
    .cc-rp-layout-compact .cc-rp-grid.cc-rp-scrollable::-webkit-scrollbar,
    .cc-rp-layout-compact .cc-rp-grid.cc-rp-mobile-scrollable::-webkit-scrollbar {
        display: none;
    }
}

/* Hide carousel arrows whenever the container is too narrow for them
   to be useful — covers both small viewports and narrow columns. */
@container cc-rp (max-width: 600px) {
    .cc-rp-arrow {
        display: none !important;
    }
}
