/**
 * Related Articles Component
 * Uses the same card design as news-slider for consistency
 * Grid layout (not a slider)
 *
 * @package Bonusovekody
 * @since 2.0.0
 */

/* ============================================
 * GRID CONTAINER
 * Desktop: 3 columns
 * Tablet: 2 columns
 * Mobile: 1 column
 * ============================================ */

.related-articles {
    display: grid;
    gap: var(--space-5);
    margin: var(--space-7) 0 0 0;
}

.archive-posts.related-articles {
    margin-top: 0;
}


/* ============================================
 * NEWS CARD
 * Same styling as homepage news slider
 * White card with image, title, date
 * ============================================ */

.related-articles .news-card {
    background: var(--white);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.related-articles .news-card__link {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Card Image */
.related-articles .news-card__image {
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: var(--grey-100);
    position: relative;
}

.related-articles .news-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.related-articles .news-card__img img {
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* Card Content */
.related-articles .news-card__content {
    padding: var(--space-7);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--space-3);
    flex-grow: 1;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    border-right: 1px solid #E8E8E8;
    border-bottom: 1px solid #E8E8E8;
    border-left: 1px solid #E8E8E8;
}

/* Card Title */
.related-articles .news-card__title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-base);
    color: #1A1A1A;
    margin: 0;
}

/* Card Date */
.related-articles .news-card__date {
    font-size: var(--font-size-small);
    line-height: 16px;
    color: #666;
    display: block;
}

/* ============================================
 * PAGINATION DOTS (Mobile Only)
 * ============================================ */

.related-articles__dots {
    display: none;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

.related-articles__dot {
    width: 8px;
    height: 8px;
    border-radius: 4px;
    background: #E8E8E8;
    border: none;
    cursor: pointer;
    transition: width 0.3s ease, background-color 0.3s ease;
    padding: 0;
}

.related-articles__dot--active {
    width: 48px;
    height: 8px;
    border-radius: 4px;
    background: #2D7AE9;
}

.related-articles__dot:hover {
    background: #D0D0D0;
}

.related-articles__dot--active:hover {
    background: #2563C7;
}

/* ============================================
 * ACCESSIBILITY
 * ============================================ */

.related-articles .news-card__link:focus {
    outline: var(--space-1) solid var(--blue-500);
    outline-offset: var(--space-1);
    border-radius: var(--radius-md);
}

.related-articles__dot:focus {
    outline: var(--space-1) solid var(--blue-500);
    outline-offset: var(--space-1);
}

/* ============================================
 * RESPONSIVE - DESKTOP
 * ============================================ */

@media (min-width: 1025px) {
    .related-articles {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================================
 * RESPONSIVE - TABLET
 * ============================================ */

@media (min-width: 768px) and (max-width: 1024px) {
    .related-articles {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
 * RESPONSIVE - MOBILE
 * ============================================ */

@media (max-width: 767px) {
    .related-articles-wrapper {
        margin: var(--space-7) calc(-1 * var(--container-padding)) 0;
    }

    .archive-posts .related-articles-wrapper {
        margin-top: 0;
    }

    /* When inside padded containers (entry-content, etc.), respect their padding */
    .entry-content .related-articles-wrapper,
    .post-content .related-articles-wrapper,
    .article-content .related-articles-wrapper {
        margin-left: 0;
        margin-right: 0;
    }

    .related-articles {
        display: flex;
        gap: var(--space-4);
        margin: 0;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding: 0 var(--container-padding);
    }

    /* Remove padding when inside padded containers */
    .entry-content .related-articles,
    .post-content .related-articles,
    .article-content .related-articles {
        padding-left: 0;
        padding-right: 0;
    }

    .related-articles::-webkit-scrollbar {
        display: none;
    }

    .related-articles:not(.archive-posts) .news-card {
        flex-shrink: 0;
        scroll-snap-align: start;
        scroll-snap-stop: always;
        width: calc(100vw - var(--container-padding) * 2 - 60px);
        max-width: 340px;
    }

    /* Adjust card width when inside padded containers */
    .entry-content .related-articles .news-card,
    .post-content .related-articles .news-card,
    .article-content .related-articles .news-card {
        width: calc(100% - 60px);
    }

    .related-articles__dots {
        display: flex;
    }

    .archive-posts.related-articles {
        display: grid;
        gap: var(--space-5);
    }

    .archive-posts.related-articles .news-card {
        width: 100%;
    }
}
