/**
 * Product cards and grid — one copy, shared by the product-grid block, the /produkter/ archive and
 * the editor preview, styled from the theme's tokens rather than a private --fts-* palette.
 */

/* The block sets this to nothing: a theme band already owns the vertical rhythm around it, and two
   containers spacing the same content double-count it. */
.products-section {
    padding: 64px 0 60px;
}

.wp-block-fru-timian-product-grid.products-section {
    padding-block: 0;
}

.products__title {
    font-family: var(--wp--preset--font-family--display, "Amatic SC", cursive);
    font-weight: 700;
    font-size: 46px;
    color: var(--wp--preset--color--tekst, #1a1a1a);
    margin-bottom: 32px;
}

/*
 * The block passes `columns` and `gap` in as custom properties, never as declarations — an inline
 * `grid-template-columns` could not be overridden here. The fallbacks are the archive's own numbers,
 * which is why every rule below that names one addresses `.products__grid--arkiv`. One property
 * drives both gutters because the block's `gap` attribute did.
 */
.products__grid {
    display: grid;
    grid-template-columns: repeat(var(--fts-grid-columns, 3), 1fr);
    column-gap: var(--fts-grid-gap, 30px);
    row-gap: var(--fts-grid-gap, 48px);
}

/* The card is a positioned wrapper, not a link: the whole-card link is an overlay and the cart
   button its sibling, so the button stays reachable by keyboard. */
.prod-card {
    position: relative;
    container-name: fts-prod-kort;
    container-type: inline-size;
    display: flex;
    flex-direction: column;
    border-radius: var(--wp--custom--radius--kant, 3px);
    transition: transform 0.25s;
}

.prod-card:hover {
    transform: translateY(-3px);
}

/* The ::after covers the whole card, so it is clickable without a button nested inside an anchor. */
.prod-card__link {
    color: inherit;
    text-decoration: none;
}

.prod-card__link::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: var(--wp--custom--radius--kant, 3px);
}

.prod-card__link:hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.prod-card__link:focus-visible {
    outline: 2px solid var(--wp--preset--color--tekst, #1a1a1a);
    outline-offset: 3px;
}

/*
 * position: relative because the sale tag and the favourite heart sit on top of the image.
 *
 * No frame and no fill: the photograph is the card's own edge. A tinted box behind a `cover` image
 * shows through as a pale blue hairline wherever the card's width lands on a fraction of a pixel.
 */
.prod-card__img {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border-radius: var(--wp--custom--radius--kant, 3px);
    overflow: hidden;
}

.prod-card__img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s;
}

.prod-card:hover .prod-card__img img {
    transform: scale(1.05);
}

/* ── Sale tag and favourite heart ── */

/* Both sit above the whole-card overlay link's z-index: 1, or it paints over the tag and swallows
   the heart's clicks. */
.prod-card__sale-tag {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    padding: 5px 10px;
    border-radius: var(--wp--custom--radius--kant, 3px);
    background: var(--wp--preset--color--gul, #e09900);
    box-shadow: var(--wp--custom--skygge--kort, 0 4px 4px rgba(0, 0, 0, 0.1));
    color: var(--wp--preset--color--tekst, #1a1a1a);
    font-size: var(--wp--preset--font-size--kicker-s, 0.75rem);
    font-weight: 700;
    letter-spacing: 0.8px;
    line-height: 1;
    text-transform: uppercase;
}

.prod-card__favorite {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}

.prod-card__favorite:hover {
    transform: scale(1.15);
}

.prod-card__favorite:focus-visible {
    outline: 2px solid var(--wp--preset--color--hvit, #fff);
    outline-offset: 0;
}

/*
 * White stroke over an unknown photograph, so the drop shadow is what keeps it visible on a pale
 * one rather than a second colour that would be wrong on half the catalogue.
 */
.prod-card__favorite svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: var(--wp--preset--color--hvit, #fff);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
    transition: fill 0.15s, stroke 0.15s;
}

.prod-card__favorite[aria-pressed='true'] svg {
    fill: var(--wp--preset--color--gul, #e09900);
    stroke: var(--wp--preset--color--gul, #e09900);
}

/* ── The star row ── */

/*
 * Two layers of five glyphs, the filled one clipped to a width `fts_star_row()` sets — which is what
 * draws an exact 4.93 without a half-star glyph and without rounding the number.
 */
.fts-star-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--wp--preset--font-size--brodtekst-s, 0.875rem);
    line-height: 1;
}

.fts-stars {
    position: relative;
    display: inline-block;
    /* The track sets the box; the fill is laid over it. */
    color: var(--wp--preset--color--tekst-svak, #5a6660);
}

.fts-stars__track,
.fts-stars__fill {
    display: flex;
    gap: 2px;
}

/* The opacity sits on the track rather than on `.fts-stars`, or it dims the filled layer with it. */
.fts-stars__track {
    opacity: 0.25;
}

/* The filled layer is the rating itself, so it carries the palette's yellow rather than the text colour. */
.fts-stars__fill {
    position: absolute;
    inset: 0;
    overflow: hidden;
    color: var(--wp--preset--color--gul, #e09900);
}

/* Each glyph keeps its width inside the clipped layer, or the fill would compress rather than clip. */
.fts-stars__fill .fts-star {
    flex: 0 0 auto;
}

.fts-star-row__count {
    font-weight: 600;
    color: var(--wp--preset--color--tekst, #1a1a1a);
}

.fts-star-row__total {
    color: var(--wp--preset--color--tekst-svak, #5a6660);
}

.fts-star-row__link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
}

.fts-star-row__link:hover .fts-star-row__count {
    text-decoration: underline;
}

/* The card's own row: stars above the title, with a bare «(112)» beside them. */
.prod-card__stars {
    display: flex;
    align-items: center;
    margin-top: 12px;
}

.fts-star-row--kompakt .fts-star-row__total {
    font-size: var(--wp--preset--font-size--brodtekst-s, 0.875rem);
}

.prod-card__name {
    font-family: var(--wp--preset--font-family--brod, Figtree, system-ui, -apple-system, sans-serif);
    font-weight: 600;
    font-size: var(--wp--preset--font-size--tittel-m, 1.25rem);
    line-height: 1.3;
    margin-top: 8px;
    margin-bottom: 0;
    color: var(--wp--preset--color--tekst, #1a1a1a);
}

/*
 * The band reserves two lines for a title so everything above the price row lines up across it; the
 * archive is scanned by name and leaves titles whole.
 *
 * `overflow: hidden` here does not clip `.prod-card__link::after`: the name is `position: static`, so
 * it is not that overlay's containing block and cannot be its clipping ancestor.
 */
.wp-block-fru-timian-product-grid .prod-card__name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    min-height: 2.6em;
    overflow: hidden;
}

.prod-card__detail {
    font-family: var(--wp--preset--font-family--brod, Figtree, system-ui, -apple-system, sans-serif);
    font-size: var(--wp--preset--font-size--brodtekst-s, 0.875rem);
    line-height: 1.43;
    margin-top: 4px;
    margin-bottom: 0;
    /* One reserved line, so a product in no collection keeps its price row level with its neighbours. */
    min-height: 1.43em;
    color: var(--wp--preset--color--tekst, #1a1a1a);
}

/* `margin-top: auto` pins the row to the bottom of the card, so prices and cart buttons line up
   across a row of cards whose titles and descriptions differ in length. */
.prod-card__price-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: auto;
    padding-top: 12px;
    /* The CTA is full-width and wraps onto its own line inside this row. */
    flex-wrap: wrap;
}

.prod-card__price {
    font-family: var(--wp--preset--font-family--brod, Figtree, system-ui, -apple-system, sans-serif);
    font-weight: 500;
    font-size: var(--wp--preset--font-size--tittel-m, 1.25rem);
    color: var(--wp--preset--color--tekst, #1a1a1a);
}

/* A discounted card states the saving with the pair it already prints: the price it asks for in
   orange, the price it does not struck through beside it. The orange is `gul-tekst`, not the
   palette's `gul`, which reaches only 2.4:1 on white and fails AA for text. */
.prod-card__price-row:has(.prod-card__price-old) .prod-card__price {
    font-weight: 700;
    color: var(--wp--custom--gul-tekst, #c78800);
}

.prod-card__price-old {
    font-size: var(--wp--preset--font-size--brodtekst, 1rem);
    color: var(--wp--preset--color--tekst-svak, #5a6660);
    text-decoration: line-through;
    text-decoration-thickness: 2px;
}

/* Full width on its own line below the price, which is what puts every card's CTA at the same
   offset from the bottom. */
.prod-card__cart {
    width: 100%;
    margin-top: 8px;
    /* Lifted above the overlay link so it stays clickable and focusable. */
    position: relative;
    z-index: 2;
}

/*
 * The sold-out CTA, keyed on `:disabled` rather than on `.prod-card__sold-out` so it cannot drift
 * from the attribute that makes the button inert. `:disabled` weighs (0,2,0) and beats `.cart-btn`;
 * the `:hover` pair weighs (0,3,0) and beats `.cart-btn:hover`, which would otherwise brighten and
 * lift a button that does nothing.
 */
.cart-btn:disabled,
.cart-btn:disabled:hover {
    background: var(--wp--preset--color--lys-blaa, #eaf8fb);
    color: var(--wp--preset--color--tekst-svak, #5a6660);
    cursor: default;
    filter: none;
    transform: none;
}

/* Sits where the sold-out note would, and never both. Quieter than the price beside it: a nudge,
   not the headline. */
.prod-card__low-stock {
    font-size: var(--wp--preset--font-size--brodtekst-s, 0.875rem);
    /* tekst, not gul: #e09900 on white is about 2.3:1 and fails WCAG AA at this size. */
    color: var(--wp--preset--color--tekst, #1a1a1a);
    font-weight: 600;
    margin-left: auto;
}

/* ── Labelled add-to-cart button ── */

/*
 * `.cart-btn` is the class the cart script binds to (`.cart-btn.prod-card__cart[data-variant-id]`,
 * docs/cart.md) and the one `.cart-btn--loading` / `--success` decorate in mini-cart.css, so both
 * names stay on the element though only `.prod-card__cart` carries layout.
 */
.cart-btn {
    padding: 10px 16px;
    border-radius: var(--wp--custom--radius--kant, 3px);
    background: var(--wp--preset--color--gul, #e09900);
    color: var(--wp--preset--color--hvit, #fff);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    font-family: var(--wp--preset--font-family--brod, Figtree, system-ui, -apple-system, sans-serif);
    font-size: var(--wp--preset--font-size--brodtekst-s, 0.875rem);
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.1s, filter 0.15s, background 0.2s;
}

.cart-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.08);
}

.cart-btn:focus-visible {
    outline: 2px solid var(--wp--preset--color--tekst, #1a1a1a);
    outline-offset: 2px;
}

.cart-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/*
 * "Legg i handlekurv" needs about 168px of card to stay on one line, so a narrow card swaps it for
 * the short label beside the icon. `aria-label` is the accessible name in both states. The card's own
 * width decides it and never the window's, since a card in a four-up grid on a desktop is narrower
 * than one in a two-up grid on a phone. The sold-out button is left out, having no icon.
 */
.prod-card__cart-label {
    white-space: nowrap;
}

.prod-card__cart-label--kort {
    display: none;
}

@container fts-prod-kort (width < 180px) {
    .prod-card__cart:not(.prod-card__sold-out) .prod-card__cart-label--lang {
        display: none;
    }

    .prod-card__cart:not(.prod-card__sold-out) .prod-card__cart-label--kort {
        display: inline;
    }
}

/* Screen-reader-only text, used for the card overlay link's accessible name. */
.fts-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 1200px) {
    /* minmax(0, 1fr): a long product name must not widen its column. */
    .products__grid--arkiv {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/*
 * The block's grid scrolls sideways once its cards would be too narrow, and there is no breakpoint in
 * it: `columns` is the author's, 1 to 6, so no fixed container width can be the right switch. What
 * matters is the narrowest a card may be, and `minmax()` states that — the crossover falls where
 * `N × 200 + gaps` stops fitting. 200px is where this card's full CTA, icon and label, sits on one
 * line. `min( 200px, 100% )` floors at a container narrower than one card rather than overflowing it.
 *
 * A grid, not a flex track, because a grid still wraps: more products than columns stays rows and the
 * rows scroll together, where a `flex-basis` of `1/N` would put every product in one very long swipe.
 *
 * The archive keeps its wrapped two-up grid instead. An archive is scanned, so a carousel there would
 * hide most of the catalogue behind a swipe and make its pagination a claim about products the reader
 * cannot see.
 */
.wp-block-fru-timian-product-grid .products__grid {
    grid-template-columns: repeat(var(--fts-grid-columns, 3), minmax(min(200px, 100%), 1fr));
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    /*
     * A swipe past the end of the track must not become a browser back-navigation, which is what it
     * is on iOS and on a trackpad without this.
     */
    overscroll-behavior-x: contain;
    /*
     * `overflow-x` clips the other axis too, and `.prod-card:hover` lifts the card 3px — so the
     * track carries the room for that lift rather than shearing it off.
     */
    padding-block: 4px 12px;
    /*
     * No scrollbar: the cut card at the right edge is the affordance. No `tabindex="0"` on the track
     * either — every card holds a link and a button, so tabbing already scrolls it into view.
     */
    scrollbar-width: none;
}

.wp-block-fru-timian-product-grid .products__grid::-webkit-scrollbar {
    display: none;
}

.wp-block-fru-timian-product-grid .products__grid > .prod-card {
    scroll-snap-align: start;
}

@media (max-width: 768px) {
    .products__grid--arkiv {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 16px;
        row-gap: 32px;
    }

    .products__title {
        font-size: 36px;
    }

    /*
     * The heart's 32px hit area shares the image's top strip with the sale tag at this width, and it
     * opens a shortlist that lives in the tab it was tapped in. The tag is the one worth the strip.
     */
    .prod-card__favorite {
        display: none;
    }

    /*
     * Asking price and struck price on one line in about 150px. Below the width where they fit, the
     * struck price wraps under the asking one and the CTA stays level with its neighbours, because
     * `margin-top: auto` anchors the row from the bottom.
     */
    .prod-card__price-row {
        column-gap: 8px;
    }

    .prod-card__price-old {
        font-size: var(--wp--preset--font-size--brodtekst-s, 0.875rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .prod-card,
    .prod-card__img img,
    .prod-card__favorite,
    .cart-btn {
        transition: none;
    }

    .prod-card:hover,
    .prod-card__favorite:hover,
    .cart-btn:hover {
        transform: none;
    }

    .cart-btn[aria-busy="true"]::before {
        animation: none;
    }

    .prod-card:hover .prod-card__img img {
        transform: none;
    }
}
