/**
 * B11 - Articles Section Styles
 *
 * Three layouts: grid, list, carousel.
 * CSS Isolation: All classes use .saly-ps- prefix
 *
 * FIGMA DESIGN: Node 23614-95602 (2025-11-17)
 * - Spartan font (Bold 700, Medium 500)
 * - 3-column grid with 16px gap
 * - Purple navigation arrows #4B1195
 */

/* ===================================
   SPARTAN FONT IMPORT (from Figma)
   =================================== */
@import url('https://fonts.googleapis.com/css2?family=Spartan:wght@500;700&display=swap');

/* BASE CONTAINER */
.saly-ps-block-articles {
    padding: 3rem 1rem;
    margin-bottom: 2rem;
    width: 100%;
    container-type: inline-size;
    container-name: articles-block;

    /* Dynamic background color and padding (from builder) */
    background-color: var(--saly-ps-b11-bg-color, transparent);
    padding: var(--saly-ps-b11-padding, 3rem 1rem);
}

.saly-ps-articles-wrapper {
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;  /* 32px default gap between header and grid */
    overflow: hidden;  /* Hide article padding overflow in carousel mode */
}

/* Carousel overflow container */
.saly-ps-articles-carousel-container {
    overflow: hidden;
    width: 100%;
}

/* HEADER ROW (Figma: Node 23614-95603) */
.saly-ps-articles-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;  /* Allow wrapping on mobile */
}

/* Left side: Title + Subtitle stacked */
.saly-ps-articles-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 0 1 auto;  /* Don't grow, can shrink */
}

.saly-ps-articles-title {
    font-family: 'Spartan', sans-serif;
    font-size: 1.125rem;  /* 18px - Figma spec */
    font-weight: 700;  /* Bold */
    line-height: 1.556;  /* 28px / 18px */
    letter-spacing: -0.36px;  /* Figma spec */
    color: #333333;  /* Figma Main/Black */
    margin: 0;
}

/* SUBTITLE (NEW - from builder) - Close to title on desktop, full width on mobile */
.saly-ps-articles-subtitle {
    font-family: 'Spartan', sans-serif;
    font-size: 0.875rem;  /* 14px */
    font-weight: 500;  /* Medium */
    line-height: 1.5;
    color: #718096;  /* Gray */
    margin: 0;
}

/* HEADER BUTTONS CONTAINER (Figma: Node 23812-107609) */
.saly-ps-articles-header-buttons {
    display: flex;
    align-items: center;
    gap: 1rem;  /* 16px - Figma spec */
}

/* "Zobacz wszystkie artykuły" BUTTON (Figma Desktop: Node 23812-107610, Mobile: 23943-94802) */
.saly-ps-articles-view-all-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--saly-ps-primary-color, #4B1195);
    border-radius: 4px;
    color: var(--saly-ps-primary-color, #4B1195);
    font-family: 'Spartan', sans-serif;
    font-size: 0.75rem;  /* 12px */
    font-weight: 600;  /* SemiBold */
    line-height: 1.667;  /* 20px / 12px */
    letter-spacing: -0.24px;  /* Figma spec */
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    white-space: nowrap;
}

.saly-ps-articles-view-all-btn:hover {
    background: var(--saly-ps-primary-color, #4B1195);
    color: white;
}

/* Responsive button text - default: show full text, hide short */
.saly-ps-view-all-short {
    display: none;
}

/* GRID LAYOUT */
.saly-ps-articles-grid {
    display: grid;
    gap: 1rem;  /* 16px - Figma specification (was 2rem/32px) */
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.saly-ps-articles-grid[data-saly-ps-columns="2"] { grid-template-columns: repeat(2, 1fr); }
.saly-ps-articles-grid[data-saly-ps-columns="3"] { grid-template-columns: repeat(3, 1fr); }
.saly-ps-articles-grid[data-saly-ps-columns="4"] { grid-template-columns: repeat(4, 1fr); }

/* CAROUSEL MODE: Convert grid to flexbox for sliding animation */
.saly-ps-articles-grid--carousel {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 1rem !important;  /* 16px gap between items (preserves border-radius) */
    transform: translateX(0);
}

/* Carousel items: no margin needed, gap handles spacing */
.saly-ps-articles-grid--carousel .saly-ps-article-card {
    flex: 0 0 auto;
    flex-shrink: 0;
}

/* Desktop carousel: width = (100% - gaps) / N */
.saly-ps-articles-grid--carousel[data-saly-ps-columns="2"] .saly-ps-article-card {
    width: calc((100% - 1rem) / 2);  /* 2 items, 1 gap */
}

.saly-ps-articles-grid--carousel[data-saly-ps-columns="3"] .saly-ps-article-card {
    width: calc((100% - 2rem) / 3);  /* 3 items, 2 gaps */
}

.saly-ps-articles-grid--carousel[data-saly-ps-columns="4"] .saly-ps-article-card {
    width: calc((100% - 3rem) / 4);  /* 4 items, 3 gaps */
}

/* LIST LAYOUT */
.saly-ps-articles-list {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.saly-ps-articles-list .saly-ps-article-card {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
}

/* CAROUSEL LAYOUT */
.saly-ps-articles-carousel {
    display: flex;
    gap: 2rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 1rem;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 #f7fafc;
}

.saly-ps-articles-carousel::-webkit-scrollbar {
    height: 8px;
}

.saly-ps-articles-carousel::-webkit-scrollbar-track {
    background: #f7fafc;
    border-radius: 4px;
}

.saly-ps-articles-carousel::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.saly-ps-articles-carousel .saly-ps-article-card {
    flex: 0 0 350px;
    scroll-snap-align: start;
}

/* ARTICLE CARD (Figma: Node 23614-95610) */
.saly-ps-article-card {
    display: flex;
    flex-direction: column;
    border-radius: 8px;  /* Figma spec */
    overflow: hidden;
    background: #F8F9FA;  /* Figma: Grayscale/Gray 100 - unified card background */
}

/* IMAGE SECTION (Figma: Node 23614-95611) */
.saly-ps-article-image-link {
    display: block;
    width: 100%;
    line-height: 0;
    overflow: hidden;
}

.saly-ps-article-image {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
}

/* TEXT SECTION (Figma: Node 23614-95614) */
.saly-ps-article-content {
    background: #F8F9FA;  /* Figma: Grayscale/Gray 100 */
    padding: 24px;  /* Figma spec */
    display: flex;
    flex-direction: column;
    gap: 8px;  /* Figma spec */
    cursor: pointer;
}

/* DATE (Figma: Node 23614-95615) */
.saly-ps-article-date {
    font-family: 'Spartan', sans-serif;
    font-weight: 500;  /* Medium */
    font-size: 0.875rem;  /* 14px */
    line-height: 1.714;  /* 24px / 14px */
    letter-spacing: -0.28px;  /* Figma spec */
    color: #333333;  /* Figma: Main/Black */
    text-decoration: none;
    display: block;
    width: 100%;
}

.saly-ps-article-date:hover {
    color: #333333;
}

/* TITLE (Figma: Node 23614-95616) */
.saly-ps-article-title {
    font-family: 'Spartan', sans-serif;
    font-weight: 700;  /* Bold */
    font-size: 1rem;  /* 16px - Figma spec */
    line-height: 1.5;  /* 24px / 16px */
    letter-spacing: -0.32px;  /* Figma spec */
    color: #333333;  /* Figma: Main/Black */
    margin: 0;
}

.saly-ps-article-title a {
    color: #333333;
    text-decoration: none;
    display: block;
    width: 100%;
}

.saly-ps-article-title a:hover {
    color: #333333;
}

/* EXCERPT (NEW - conditional display) */
.saly-ps-article-excerpt {
    font-family: 'Spartan', sans-serif;
    font-size: 0.875rem;  /* 14px */
    font-weight: 400;  /* Regular */
    line-height: 1.5;
    color: #718096;  /* Gray */
    margin: 0;
    display: block;
}

/* AUTHOR (NEW - conditional display) */
.saly-ps-article-author {
    font-family: 'Spartan', sans-serif;
    font-size: 0.75rem;  /* 12px */
    font-weight: 500;  /* Medium */
    color: #718096;  /* Gray */
    display: block;
}

/* "CZYTAJ WIĘCEJ" LINK (Figma: Node 23614-95617) - now with custom text support */
.saly-ps-article-link {
    font-family: 'Spartan', sans-serif;
    font-weight: 700;  /* Bold */
    font-size: 0.875rem;  /* 14px */
    line-height: 1.714;  /* 24px / 14px */
    letter-spacing: -0.28px;  /* Figma spec */
    color: var(--saly-ps-primary-color, #4B1195);
    text-decoration: none;
    display: block;
    width: 100%;
}

.saly-ps-article-link:hover {
    color: var(--saly-ps-primary-color, #4B1195);
    text-decoration: underline;
}

/* NO ARTICLES */
.saly-ps-no-articles {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: #718096;
    font-size: 1.125rem;
}

/* NAVIGATION ARROW BUTTONS (Figma: Node 23812-107611, 23812-107612) */
.saly-ps-articles-nav-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;  /* 18px icon + 12px padding each side = ~42px, rounded to 40px */
    height: 40px;  /* 18px icon + 11px padding top/bottom = ~40px */
    padding: 11px 12px;
    background: transparent;
    border: 1px solid var(--saly-ps-primary-color, #4B1195);
    border-radius: 4px;
    color: var(--saly-ps-primary-color, #4B1195);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
}

.saly-ps-articles-nav-button:hover {
    background: var(--saly-ps-primary-200, #d4c4f7);
    border-color: var(--saly-ps-primary-200, #d4c4f7);
    color: var(--saly-ps-primary-color, #4B1195);
}

.saly-ps-articles-nav-button:focus {
    outline: none;
}

.saly-ps-articles-nav-button:disabled {
    border-color: #CBD5E0;
    color: #CBD5E0;
    cursor: not-allowed;
    opacity: 0.6;
}

.saly-ps-articles-nav-button:disabled:hover {
    background: transparent;
}

.saly-ps-articles-nav-button svg {
    width: 18px;  /* Figma icon size */
    height: 18px;
    flex-shrink: 0;
}

/* RESPONSIVE */
@media (max-width: 1024px) {
    .saly-ps-articles-grid[data-saly-ps-columns="4"] {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    /* Header stacks on tablet */
    .saly-ps-articles-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .saly-ps-articles-header-buttons {
        width: 100%;
        justify-content: space-between;
    }

    .saly-ps-articles-view-all-btn {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .saly-ps-articles-grid[data-saly-ps-columns="3"],
    .saly-ps-articles-grid[data-saly-ps-columns="4"] {
        grid-template-columns: repeat(2, 1fr);
    }

    .saly-ps-articles-list .saly-ps-article-card {
        grid-template-columns: 1fr;
    }

    .saly-ps-articles-carousel .saly-ps-article-card {
        flex: 0 0 280px;
    }
}

/* MOBILE STYLES - Media Queries (production fallback) */
@media (max-width: 640px) {
    /* Mobile layout (Figma: Node 23870-94526) */
    .saly-ps-block-articles {
        padding: 0 1rem;  /* 16px horizontal padding */
    }

    .saly-ps-articles-wrapper {
        gap: 1.5rem;  /* 24px gap between header and grid - Figma mobile spec */
    }

    /* Mobile header: title + buttons on first row, subtitle full width on second row */
    .saly-ps-articles-header-left {
        flex: 1 1 100%;  /* Full width to force wrapping */
        order: 1;  /* Title/subtitle first */
    }

    .saly-ps-articles-title {
        flex: 0 1 auto;  /* Title takes only needed space */
    }

    .saly-ps-articles-subtitle {
        flex: 1 1 100%;  /* Subtitle takes full width */
        margin-top: 0.5rem;  /* Space above subtitle on mobile */
    }

    .saly-ps-articles-header-buttons {
        order: 0;  /* Buttons appear on same line as title */
        margin-left: auto;  /* Push to right */
    }

    /* Mobile: shortened button text "Wszystkie" */
    .saly-ps-view-all-full {
        display: none;  /* Hide "Zobacz wszystkie artykuły" */
    }

    .saly-ps-view-all-short {
        display: block;  /* Show "Wszystkie" */
    }

    .saly-ps-articles-grid {
        grid-template-columns: 1fr !important;
    }

    /* Mobile carousel: 1 article = 100% width (padding-right inside via border-box) */
    .saly-ps-articles-grid--carousel .saly-ps-article-card {
        width: 100% !important;
    }

    /* Article card maintains Figma specs on mobile (same as desktop) */
    .saly-ps-article-content {
        padding: 24px;  /* Same as desktop - Figma spec */
        gap: 8px;  /* Same as desktop - Figma spec */
    }

    .saly-ps-article-title {
        font-size: 1rem;  /* 16px - same as desktop */
        line-height: 1.5;  /* 24px / 16px */
        letter-spacing: -0.32px;
    }

    .saly-ps-article-date {
        font-size: 0.875rem;  /* 14px - same as desktop */
    }

    .saly-ps-article-link {
        font-size: 0.875rem;  /* 14px - same as desktop */
    }
}

/* MOBILE STYLES - Container Queries (test runner support) */
@container articles-block (max-width: 640px) {
    .saly-ps-block-articles {
        padding: 0 1rem;
    }

    .saly-ps-articles-wrapper {
        gap: 1.5rem;
    }

    /* Mobile header: title + buttons on first row, subtitle full width on second row */
    .saly-ps-articles-header-left {
        flex: 1 1 100%;  /* Full width to force wrapping */
        order: 1;  /* Title/subtitle first */
    }

    .saly-ps-articles-title {
        flex: 0 1 auto;  /* Title takes only needed space */
    }

    .saly-ps-articles-subtitle {
        flex: 1 1 100%;  /* Subtitle takes full width */
        margin-top: 0.5rem;  /* Space above subtitle on mobile */
    }

    .saly-ps-articles-header-buttons {
        order: 0;  /* Buttons appear on same line as title */
        margin-left: auto;  /* Push to right */
    }

    .saly-ps-view-all-full {
        display: none;
    }

    .saly-ps-view-all-short {
        display: block;
    }

    .saly-ps-articles-grid {
        grid-template-columns: 1fr !important;
    }

    /* Mobile carousel: 1 article = 100% width (padding-right inside via border-box) */
    .saly-ps-articles-grid--carousel .saly-ps-article-card {
        width: 100% !important;
    }

    .saly-ps-article-content {
        padding: 24px;
        gap: 8px;
    }

    .saly-ps-article-title {
        font-size: 1rem;
        line-height: 1.5;
        letter-spacing: -0.32px;
    }

    .saly-ps-article-date {
        font-size: 0.875rem;
    }

    .saly-ps-article-link {
        font-size: 0.875rem;
    }
}

/* ACCESSIBILITY */
@media (prefers-reduced-motion: reduce) {
    .saly-ps-article-card,
    .saly-ps-article-image,
    .saly-ps-article-link {
        transition: none;
    }

    .saly-ps-article-card:hover .saly-ps-article-image {
        transform: none;
    }
}
