/* =====================================================================
   electro_storefront — product cards + grids + rails (phase 2)

   Single owner of the product tile look. The same `.sf-card` markup is
   rendered server-side (templates/includes/storefront/cards.html) and
   client-side (recommendations.js, creative.store.js wishlist page) —
   so one stylesheet styles every tile in the storefront.
   Namespace: .sf-root (body) → .sf-card / .sf-grid / .sf-rail.
   ===================================================================== */

/* ------------------------------------------------------------------ card */
.sf-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--sf-surface, #fff);
    border: 1px solid var(--sf-border);
    border-radius: var(--sf-radius, 2px);
    transition: box-shadow .25s ease, border-color .25s ease;
    overflow: hidden;
}

.sf-card:hover {
    border-color: #cfcfcf;
    box-shadow: var(--sf-shadow-md, 0 6px 18px rgba(51, 62, 72, .10));
    z-index: 5;
}

.sf-card.is-image-only {
    border: 0;
    background: transparent;
}

/* -------------------------------------------------------------- media */
.sf-card__media {
    position: relative;
    margin: 10px;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sf-card__link {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

.sf-card__link:hover {
    text-decoration: none;
}

.sf-card__image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform .35s ease;
}

.sf-card:hover .sf-card__image {
    transform: scale(1.04);
}

.sf-card__fallback {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
    justify-content: center;
    color: #b9c2cc;
    text-align: center;
    padding: 12px;
}

.sf-card__fallback svg {
    width: 48px;
    max-width: 100%;
    height: auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sf-card__fallback small {
    font-size: 11px;
    color: var(--sf-text-muted);
}

.sf-card__caption {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    background: rgba(51, 62, 72, .82);
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
    padding: 6px 10px;
    text-align: center;
    direction: ltr;
}

/* -------------------------------------------------------------- badges */
/* Badges reuse the .sf-badge primitive from base.css
   (background, weight, sizing). This container only owns placement. */
.sf-card__badges {
    position: absolute;
    top: 6px;
    inset-inline-start: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
    z-index: 6;
}

.sf-card__rank {
    position: absolute;
    top: 6px;
    inset-inline-end: 6px;
    min-width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding-inline: 6px;
    background: var(--sf-dark);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    border-radius: var(--sf-radius, 2px);
}

/* -------------------------------------------------------- hover tools */
.sf-card__hover-tools {
    position: absolute;
    top: 6px;
    inset-inline-end: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 7;
}

.sf-card__tool {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--sf-border);
    border-radius: var(--sf-radius, 2px);
    color: var(--sf-dark);
    cursor: pointer;
    transition: background .2s ease, color .2s ease, border-color .2s ease;
}

.sf-card__tool:hover {
    background: var(--sf-primary);
    border-color: var(--sf-primary);
    color: #000;
}

.sf-card__tool.active,
.sf-card__tool.is-active {
    background: var(--sf-primary);
    border-color: var(--sf-primary);
    color: #000;
}

/* --------------------------------------------------------------- body */
.sf-card__body {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 0 14px 14px;
    flex: 1;
}

.sf-card.is-featured .sf-card__body {
    padding: 0 16px 16px;
}

.sf-card__eyebrow {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--sf-primary-active);
}

.sf-card__title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--sf-link, var(--sf-dark));
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 2.8em;
}

.sf-card__title:hover {
    color: var(--sf-primary-active);
    text-decoration: none;
}

.sf-card__summary {
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    color: var(--sf-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sf-card__rating {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--sf-text-muted);
}

.sf-card__rating .sf-stars {
    font-size: 13px;
}

.sf-card__rating-count {
    color: var(--sf-text-muted);
}

/* -------------------------------------------------------------- price */
.sf-card__pricing {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: auto;
}

.sf-price--card {
    font-size: 16px;
    font-weight: 600;
    color: var(--sf-dark);
}

.sf-price--card.is-sale {
    color: var(--sf-price-sale);
}

.sf-card__price-note {
    font-size: 12px;
    color: var(--sf-text-muted);
}

/* -------------------------------------------------------------- stock */
.sf-card__stock {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--sf-text-muted);
}

.sf-card__stock i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sf-success);
    flex-shrink: 0;
}

.sf-card__stock.is-out-of-stock i {
    background: var(--sf-danger);
}

.sf-card__stock.is-out-of-stock {
    color: var(--sf-danger);
}

/* ------------------------------------------------------------ actions */
.sf-card__actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.sf-card__atc {
    flex: 1;
    justify-content: center;
    gap: 8px;
    width: 100%;
}

.sf-card__atc.sf-btn--neutral:hover {
    background: var(--sf-primary);
    border-color: var(--sf-primary);
    color: #000;
}

/* ---------------------------------------------------------- grids */
.sf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px 12px;
    direction: ltr;
}

[dir="rtl"] .sf-grid {
    direction: rtl;
}

.sf-grid--wide {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

.sf-grid--tight {
    gap: 14px 10px;
}

.sf-grid.is-single {
    grid-template-columns: minmax(0, 250px);
    justify-content: start;
}

.sf-grid.is-pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 520px;
}

/* ---------------------------------------------------------- rails */
/* .sf-rail-wrap positions the nav buttons; .sf-rail scrolls. */
.sf-rail-wrap {
    position: relative;
}

.sf-rail {
    position: relative;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(190px, calc((100% - 70px) / 6));
    gap: 14px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.sf-rail > * {
    scroll-snap-align: start;
}

.sf-rail::-webkit-scrollbar {
    display: none;
}

.sf-rail__nav {
    position: absolute;
    top: calc(50% - 62px);
    width: 34px;
    height: 34px;
    display: none;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--sf-border);
    border-radius: 50%;
    color: var(--sf-dark);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(51, 62, 72, .15);
    z-index: 10;
}

.sf-rail__nav.is-prev { inset-inline-start: -14px; }
.sf-rail__nav.is-next { inset-inline-end: -14px; }

.sf-rail__nav:hover {
    background: var(--sf-primary);
    border-color: var(--sf-primary);
    color: #000;
}

.sf-rail-wrap.has-overflow .sf-rail__nav { display: inline-flex; }

.sf-rail__nav svg {
    width: 14px;
    height: 14px;
}

/* ------------------------------------------------------- skeletons */
.sf-skeleton-card {
    border: 1px solid var(--sf-border);
    background: #fff;
    padding: 0;
    overflow: hidden;
}

.sf-skeleton-card__img {
    aspect-ratio: 1 / 1;
    margin: 10px;
    background: linear-gradient(100deg, #f4f4f4 40%, #ececec 50%, #f4f4f4 60%) 0 0 / 220% 100%;
    animation: sf-card-shimmer 1.2s linear infinite;
}

.sf-skeleton-card__body {
    padding: 0 14px 16px;
    display: grid;
    gap: 9px;
}

.sf-skeleton-card__line {
    height: 12px;
    border-radius: 2px;
    background: #f1f1f1;
}

.sf-skeleton-card__line--wide { width: 100%; }
.sf-skeleton-card__line--short { width: 55%; }
.sf-skeleton-card__line--price { width: 40%; height: 16px; background: #ececec; }

/* ------------------------------------------------- responsive */
@media (max-width: 575.98px) {
    .sf-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 8px;
    }

    .sf-grid.is-single {
        grid-template-columns: minmax(0, 1fr);
    }

    .sf-card__title { font-size: 13px; }
    .sf-card__pricing { font-size: 14px; }
    .sf-card__body { padding: 0 10px 12px; }
    .sf-card__media { margin: 10px; }
    .sf-rail { grid-auto-columns: minmax(160px, 60vw); }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .sf-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
    .sf-rail { grid-auto-columns: minmax(180px, 1fr); }
}
