/* ============================================================================
   Shared benefit-grid styles
   Loaded by includes/_benefit_grid.php → used by search (s.php) and
   view-all (module.php) pages across every template.

   Card visuals come from each template's product-thumb.php — this file only
   owns layout (grid columns, toolbar, toggle/filter affordances). Brand color
   for filter/toggle "active" states is themed via the --brand-color CSS var
   set inline on the section by _benefit_grid.php (reads from $set['color1']).
   ============================================================================ */

.benefit-grid-section {
    /* RTL is pinned at the section level so heading, toolbar, and grid all
       flow right-to-left even on templates that don't declare dir="rtl" on
       the document (e.g. top). No-op for templates that already declare RTL. */
    direction: rtl;
    width: 100%;
    /* Cap the section width and center it so the grid sits with comfortable
       page margins and the 4-col cells land close to the cards' natural
       327px width — minimizes internal whitespace between cards while giving
       the page real left/right margin. 1500px - 120px gutters = 1380px
       content area, divided by 4 = 345px per cell (cards at 327 sit centered
       with ~18px of breathing room each side, instead of the ~105px gap a
       wider section produced). */
    max-width: 1500px;
    margin: 32px auto 64px;
    padding: 0 60px;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .benefit-grid-section {
        padding: 0 16px;
        margin: 16px 0 32px;
    }
}

/* -------- Page heading ----------------------------------------------------- */

/* Lives inline in the toolbar; min-width: 0 lets long titles wrap without
   pushing the controls cluster to a new line. */
.benefit-grid-heading {
    color: #0B0427;
    font-size: 36px;
    font-weight: 600;
    line-height: 40px;
    margin: 0;
    min-width: 0;
}

@media (max-width: 768px) {
    .benefit-grid-heading {
        font-size: 22px;
        line-height: 26px;
    }
}

/* When the heading is rendered standalone (empty-state path on module pages),
   restore the bottom margin so the "no results" message has breathing room
   below the title. */
.benefit-grid-section > .benefit-grid-heading {
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .benefit-grid-section > .benefit-grid-heading {
        margin-bottom: 12px;
    }
}

/* -------- Toolbar ---------------------------------------------------------- */

.benefit-grid-toolbar {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.benefit-grid-toolbar__count {
    font-size: 18px;
    font-weight: 500;
    color: #0B0427;
}

/* Controls cluster (filter + view toggle). Anchored to the inline-end of the
   toolbar via auto-margin so it sits at the visual left in RTL, regardless of
   whether the count chip on the right is rendered (module pages hide it).
   margin-inline-start consumes the leading space, pushing the cluster the
   other way. */
.benefit-grid-toolbar__controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-inline-start: auto;
}

.benefit-grid-toolbar__count-value {
    font-weight: 700;
    margin: 0 4px;
}

/* Mobile: heading right, toggle pushed to far left (row 1); count on its own
   row 2 (right-aligned via RTL flow). */
@media (max-width: 768px) {
    .benefit-grid-toolbar__controls {
        order: 1;
        margin-inline-start: auto;
    }
    .benefit-grid-toolbar__count {
        order: 2;
        flex-basis: 100%;
        margin-inline-start: 0;
    }
}

/* View toggle — mobile only. Two icon buttons grouped together, active one
   filled with brand color. Desktop ignores the toggle entirely (always 5-up). */
.benefit-grid-toolbar__view {
    display: none;
    gap: 4px;
}

@media (max-width: 768px) {
    .benefit-grid-toolbar__view {
        display: inline-flex;
    }
}

.benefit-grid-toolbar__view-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid #D9D9E0;
    border-radius: 8px;
    background: transparent;
    color: #46494F;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.benefit-grid-toolbar__view-btn i {
    font-size: 16px;
    line-height: 1;
}

.benefit-grid-toolbar__view-btn.is-active {
    background: var(--brand-color, #2020B3);
    border-color: var(--brand-color, #2020B3);
    color: var(--on-brand, #fff);
}

/* -------- Grid ------------------------------------------------------------- */

.benefit-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

/* Cards keep their natural max-width: 327px (from card.css, sized for the
   homepage swiper's thumbnail resolution) so images render at source
   resolution instead of upscaling. Cells are wider than 327 — especially on
   mobile 1-col — so we explicitly center the card inside its container.
   justify-items: center on the grid is a no-op here because .card-container
   is display: block (filling its cell), so the card.product inside is what
   needs the auto-margin centering. */
.benefit-grid .card.product {
    margin: 0 auto;
}

@media (max-width: 1099px) {
    .benefit-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .benefit-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
}

/* Card sizing notes:
   Cards keep their default max-width: 327px from card.css (matches the
   homepage swiper, which is what the thumbnail() function targets). Cells
   are wider than that at 4-col, so cards sit centered in their cells via
   .benefit-grid { justify-items: center } above. We don't override card
   max-width here — letting it stay 327 keeps images crisp (no upscaling
   past the 350px thumbnail source).

   Card typography refinements come from card.css via :is(.benefit-section,
   .benefit-grid) selectors — single source of truth, no need to mirror
   those rules here. */

/* Wrapping link for non-self-wrapping product-thumbs (egged/top/couponia +
   shared includes/product-thumb.php). Lets the whole card surface be
   clickable while staying invisible visually — strips default <a> styling
   and acts as a block container so the inner card markup keeps its natural
   dimensions. Corporate_new's product-thumb supplies its own anchor and
   doesn't pass through here. */
.benefit-card-link,
.benefit-card-link:hover,
.benefit-card-link:focus,
.benefit-card-link:active {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* Mobile 1-col toggle. JS adds .benefit-grid-section--mobile-1col on click;
   the column rule flips and (separately) JS strips the .mobile-small-card
   modifier from every card so they render at full size again. We don't
   try to undo .mobile-small-card with CSS overrides — flipping the class
   in JS gives cleaner, less brittle results. */
@media (max-width: 768px) {
    .benefit-grid-section--mobile-1col .benefit-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* -------- Empty state ------------------------------------------------------ */

.benefit-grid-empty {
    width: 100%;
    /* Tight vertical padding: heading sits just above and suggestions just
       below, both of which carry their own spacing, so the empty-state line
       only needs minimal breathing room of its own. */
    padding: 16px 20px;
    text-align: center;
    font-size: 22px;
    color: #46494F;
}

@media (max-width: 768px) {
    .benefit-grid-empty {
        font-size: 18px;
        padding: 12px 20px;
    }
}

/* -------- Suggestion list -------------------------------------------------- */

/* Used by the unified includes/suggestion_list.php — same .benefit-grid below
   means card layout matches the search/module grid. Only the chrome above
   the cards differs: an optional "product doesn't exist" lead message
   (broken-link flow), then the "suggestions for you" heading. */

.suggestion-list {
    direction: rtl;
    width: 100%;
    max-width: 1500px;
    margin: 32px auto 64px;
    padding: 0 60px;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .suggestion-list {
        padding: 0 16px;
        margin: 16px 0 32px;
    }
}

.suggestion-list__lead-message {
    color: #0B0427;
    font-size: 28px;
    font-weight: 500;
    line-height: 32px;
    margin: 0 0 12px;
}

.suggestion-list__heading {
    color: #0B0427;
    font-size: 24px;
    font-weight: 600;
    line-height: 30px;
    margin: 0 0 20px;
}

@media (max-width: 768px) {
    .suggestion-list__lead-message {
        font-size: 22px;
        line-height: 26px;
    }
    .suggestion-list__heading {
        font-size: 20px;
        line-height: 26px;
        margin-bottom: 12px;
    }
}
