/**
 * Portada de la biblioteca (Modules\ShopUI\ShopShelves): filas horizontales
 * con título, flechas (anterior clara, siguiente morada), «Ver todo» oscuro y
 * tarjetas (imagen y, abajo en gris, título, categoría, favoritos y carrito).
 * Textos y fuentes con los tokens --rws-* de tokens.css (claro y oscuro); los
 * colores propios de la fila, abajo. Sin sombras; el único degradado es el de
 * la categoría (pedido del usuario, el de la barra de descargas).
 *
 * @package RecursosWorship\Modules\ShopUI
 */

html body.rw-shop-ui {
    --rws-shelf-gap: calc(20 * var(--rws-u));
    --rws-shelf-btn: max(40px, calc(48 * var(--rws-u)));
    --rws-shelf-prev-bg: #ececec;
    --rws-shelf-prev-hover: #e0e0e0;
    --rws-shelf-prev-icon: #111111;
    --rws-shelf-next-bg: #7700ff;
    --rws-shelf-next-hover: #6600db;
    --rws-shelf-next-icon: #ffffff;
    --rws-shelf-all-bg: #111111;
    --rws-shelf-all-hover: #2b2b2b;
    --rws-shelf-all-text: #ffffff;
    --rws-shelf-card: #f4f4f4;
    --rws-shelf-media: #e9e9e9;
    /* Categoría: el morado de la barra de descargas del sidebar (más oscuro en claro, por contraste). */
    --rws-shelf-accent: linear-gradient(90deg, #bc00ff 0%, #7700ff 100%);
}

html[data-rw-mode="dark"] body.rw-shop-ui,
html:not([data-rw-mode]) body.rw-shop-ui.global-color-scheme-light {
    --rws-shelf-card: #1f1f1f;
    --rws-shelf-media: #262626;
    --rws-shelf-accent: linear-gradient(90deg, #c933ff 0%, #cfb8ff 100%);
    --rws-shelf-prev-bg: #ececec;
    --rws-shelf-prev-hover: #ffffff;
    --rws-shelf-next-bg: #8a2bff;
    --rws-shelf-next-hover: #9b47ff;
    --rws-shelf-all-bg: #2a2a2a;
    --rws-shelf-all-hover: #343434;
}

/* La portada no tiene listado: fuera el recuento de resultados de WoodMart. */
html body.rw-shop-shelves .shop-loop-head .woocommerce-result-count {
    display: none;
}

.rw-shelves {
    container: rw-shelves / inline-size;
    display: flex;
    flex-direction: column;
    gap: calc(48 * var(--rws-u));
    padding: calc(8 * var(--rws-u)) 0 calc(56 * var(--rws-u));
    font-family: var(--rws-font);
}

/* --- Cabecera de la fila ------------------------------------------------ */

.rw-shelf {
    --rws-shelf-cols: 4.25;
    min-width: 0;
}

.rw-shelf__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: calc(18 * var(--rws-u));
}

html body.rw-shop-ui .rw-shelf__title {
    margin: 0;
    padding: 0;
    color: var(--rws-text);
    font-family: var(--rws-font);
    font-size: max(20px, calc(28 * var(--rws-u)));
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
}

.rw-shelf__nav {
    display: flex;
    align-items: center;
    gap: calc(10 * var(--rws-u));
    flex: none;
}

/* Flechas: anterior clara, siguiente morada (cuadradas con esquinas suaves). */
html body.rw-shop-ui .rw-shelf__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--rws-shelf-btn);
    height: var(--rws-shelf-btn);
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: var(--rws-shelf-prev-bg);
    color: var(--rws-shelf-prev-icon);
    box-shadow: none;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

html body.rw-shop-ui .rw-shelf__arrow--next {
    background: var(--rws-shelf-next-bg);
    color: var(--rws-shelf-next-icon);
}

html body.rw-shop-ui .rw-shelf__arrow svg {
    width: 20px;
    height: 20px;
}

html body.rw-shop-ui .rw-shelf__arrow--prev:hover:not(:disabled) {
    background: var(--rws-shelf-prev-hover);
    color: var(--rws-shelf-prev-icon);
}

html body.rw-shop-ui .rw-shelf__arrow--next:hover:not(:disabled) {
    background: var(--rws-shelf-next-hover);
    color: var(--rws-shelf-next-icon);
}

html body.rw-shop-ui .rw-shelf__arrow:disabled {
    opacity: 0.4;
    cursor: default;
}

.rw-shelf.is-static .rw-shelf__arrow {
    display: none;
}

/* «Ver todo»: botón oscuro de la misma altura. */
html body.rw-shop-ui .rw-shelf__all {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--rws-shelf-btn);
    padding: 0 22px;
    border: 0;
    border-radius: 8px;
    background: var(--rws-shelf-all-bg);
    color: var(--rws-shelf-all-text);
    font-family: var(--rws-font);
    font-size: max(14px, calc(15 * var(--rws-u)));
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

html body.rw-shop-ui .rw-shelf__all:hover {
    background: var(--rws-shelf-all-hover);
    color: var(--rws-shelf-all-text);
}

html body.rw-shop-ui .rw-shelf__arrow:focus-visible,
html body.rw-shop-ui .rw-shelf__all:focus-visible,
html body.rw-shop-ui .rw-shelf-card--cover:focus-visible,
html body.rw-shop-ui .rw-shelf-card__title a:focus-visible,
html body.rw-shop-ui .rw-shelf-card__wish > a:focus-visible,
html body.rw-shop-ui .rw-shelf-card__cart:focus-visible {
    outline: 2px solid var(--rws-focus);
    outline-offset: 2px;
}

html body.rw-shop-ui .rw-shelves :focus:not(:focus-visible) {
    outline: none;
}

/* --- Fila --------------------------------------------------------------- */

/* Tarjetas visibles a la vez (la última, cortada, invita a deslizar). */
.rw-shelf--tall {
    --rws-shelf-cols: 5.25;
}

.rw-shelf--cover {
    --rws-shelf-cols: 4.25;
}

html body.rw-shop-ui .rw-shelf__track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - (var(--rws-shelf-cols) - 0.25) * var(--rws-shelf-gap)) / var(--rws-shelf-cols));
    gap: var(--rws-shelf-gap);
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
}

.rw-shelf__track::-webkit-scrollbar {
    display: none;
}

html body.rw-shop-ui .rw-shelf__item {
    min-width: 0;
    margin: 0;
    padding: 0;
    scroll-snap-align: start;
}

/* --- Tarjeta: imagen y, abajo, el cuerpo gris ----------------------------- */

html body.rw-shop-ui .rw-shelf-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin: 0;
    border-radius: 10px;
    background: var(--rws-shelf-card);
    overflow: hidden;
}

html body.rw-shop-ui .rw-shelf-card__media {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    border-radius: 0;
    background: var(--rws-shelf-media);
    overflow: hidden;
}

html body.rw-shop-ui .rw-shelf-card--tall .rw-shelf-card__media {
    aspect-ratio: 9 / 16;
}

html body.rw-shop-ui .rw-shelf-card__img {
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: cover;
    transition: transform 0.45s ease;
}

.rw-shelf-card:hover .rw-shelf-card__img {
    transform: scale(1.04);
}

/* Con video al pasar el cursor: sin zoom de la imagen y el video aparece de golpe (como en la rejilla). */
.rw-shelf-card:hover .rw-shelf-card__media:has(.rw-video-preview:not(.has-preview-error)) .rw-shelf-card__img {
    transform: none;
}

html body.rw-shop-ui .rw-shelf-card__media .rw-video-preview > video {
    transition: none;
}

.rw-shelf-card__body {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 16px 16px 18px 18px;
}

.rw-shelf-card__text {
    flex: 1;
    min-width: 0;
}

html body.rw-shop-ui .rw-shelf-card__title {
    margin: 0;
    padding: 0;
    font-family: var(--rws-font);
    font-size: max(14px, calc(16 * var(--rws-u)));
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

html body.rw-shop-ui .rw-shelf-card__title a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--rws-text);
    text-decoration: none;
}

html body.rw-shop-ui .rw-shelf-card__title a:hover {
    color: var(--rws-text);
    text-decoration: underline;
    text-decoration-color: var(--rws-underline);
    text-underline-offset: 3px;
}

html body.rw-shop-ui .rw-shelf-card__meta {
    margin: 6px 0 0;
    font-size: 13px;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rw-shelf-card__cat {
    background: var(--rws-shelf-accent);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
}

.rw-shelf-card__free {
    color: var(--rws-text-2);
}

.rw-shelf-card__cat + .rw-shelf-card__free::before {
    content: " · ";
}

/* Verticales (estrechas): título a dos líneas encima; categoría e iconos debajo. */
.rw-shelf-card--tall .rw-shelf-card__body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px 8px;
    padding: 14px;
}

.rw-shelf-card--tall .rw-shelf-card__text {
    display: contents;
}

html body.rw-shop-ui .rw-shelf-card--tall .rw-shelf-card__title {
    grid-column: 1 / -1;
    display: -webkit-box;
    min-height: 2.6em;
    font-size: max(13px, calc(15 * var(--rws-u)));
    white-space: normal;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

html body.rw-shop-ui .rw-shelf-card--tall .rw-shelf-card__title a {
    display: inline;
}

html body.rw-shop-ui .rw-shelf-card--tall .rw-shelf-card__meta {
    grid-column: 1;
    margin: 0;
}

/* Favoritos y carrito: solo el icono (el texto de WoodMart queda para lectores de pantalla). */
.rw-shelf-card__actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: none;
    margin: -6px -6px 0 0;
}

.rw-shelf-card--tall .rw-shelf-card__actions {
    grid-column: 2;
    margin: 0 -6px 0 0;
}

html body.rw-shop-ui .rw-shelf-card__wish > a,
html body.rw-shop-ui .rw-shelf-card__cart {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 8px;
    color: var(--rws-text);
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

html body.rw-shop-ui .rw-shelf-card__wish > a:hover,
html body.rw-shop-ui .rw-shelf-card__cart:hover {
    background: var(--rws-hover);
    color: var(--rws-text);
}

html body.rw-shop-ui .rw-shelf-card__wish > a.added {
    color: var(--rws-text);
}

html body.rw-shop-ui .rw-shelf-card__wish > a.added .rw-shelf-ico {
    fill: currentColor;
}

/* Cargando (WoodMart pone .loading al abrir la vista rápida o guardar en favoritos): el mismo
   preloader que sus botones de la rejilla, un arco que gira en lugar del icono. */
html body.rw-shop-ui .rw-shelf-card__wish > a.loading,
html body.rw-shop-ui .rw-shelf-card__cart.loading {
    pointer-events: none;
}

html body.rw-shop-ui .rw-shelf-card__wish > a.loading > svg,
html body.rw-shop-ui .rw-shelf-card__cart.loading > * {
    opacity: 0;
}

html body.rw-shop-ui .rw-shelf-card__wish > a.loading::after,
html body.rw-shop-ui .rw-shelf-card__cart.loading::after {
    content: "";
    position: absolute;
    top: calc(50% - 9px);
    left: calc(50% - 9px);
    display: block;
    width: 18px;
    height: 18px;
    border: 1px solid transparent;
    border-left-color: currentColor;
    border-radius: 50%;
    animation: rws-shelf-spin 450ms infinite linear;
}

@keyframes rws-shelf-spin {
    to {
        transform: rotate(360deg);
    }
}

.rw-shelf-ico {
    width: 20px;
    height: 20px;
}

/* Descarga (suscripción con acceso): el mismo icono que la rejilla (video-previews.css), en currentColor. */
.rw-shelf-ico--download {
    display: block;
    background: currentColor;
    --rws-download-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 4v11m-5-5 5 5 5-5M5 20h14' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    -webkit-mask: var(--rws-download-icon) center / contain no-repeat;
    mask: var(--rws-download-icon) center / contain no-repeat;
}

html body.rw-shop-ui .rw-shelf-card__wish .wd-added-icon,
html body.rw-shop-ui .rw-shelf-card__wish > a::before,
html body.rw-shop-ui .rw-shelf-card__wish > a:not(.loading)::after,
html body.rw-shop-ui .rw-shelf-card__cart::before,
html body.rw-shop-ui .rw-shelf-card__cart:not(.loading)::after {
    display: none;
}

html body.rw-shop-ui .rw-shelf-card__wish .wd-action-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Kits: imagen con el nombre en una píldora, como una colección. */
html body.rw-shop-ui .rw-shelf-card--cover {
    position: relative;
    text-decoration: none;
}

html body.rw-shop-ui .rw-shelf-card__chip {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 4;
    max-width: calc(100% - 24px);
    padding: 7px 14px;
    border: 1px solid var(--rws-line);
    border-radius: 999px;
    background: var(--rws-pill-bg);
    color: var(--rws-text);
    font-size: max(13px, calc(14 * var(--rws-u)));
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* --- Columnas según el ancho de la zona de filas (el sidebar se colapsa) --- */

@container rw-shelves (max-width: 1499px) {
    .rw-shelf {
        --rws-shelf-cols: 3.4;
    }

    .rw-shelf--tall {
        --rws-shelf-cols: 4.2;
    }

    .rw-shelf--cover {
        --rws-shelf-cols: 3.4;
    }
}

@container rw-shelves (max-width: 1099px) {
    .rw-shelf {
        --rws-shelf-cols: 2.6;
    }

    .rw-shelf--tall {
        --rws-shelf-cols: 3.2;
    }

    .rw-shelf--cover {
        --rws-shelf-cols: 2.6;
    }
}

@container rw-shelves (max-width: 699px) {
    .rw-shelf {
        --rws-shelf-cols: 1.22;
    }

    .rw-shelf--tall {
        --rws-shelf-cols: 2.3;
    }

    .rw-shelf--cover {
        --rws-shelf-cols: 1.6;
    }
}

/* --- Móvil -------------------------------------------------------------- */

@media (max-width: 767px) {
    html body.rw-shop-ui {
        --rws-shelf-gap: 12px;
    }

    .rw-shelves {
        gap: 32px;
        padding-top: 4px;
    }

    .rw-shelf__head {
        margin-bottom: 14px;
    }

    /* Con el dedo no hacen falta las flechas. */
    html body.rw-shop-ui .rw-shelf__arrow {
        display: none;
    }

    html body.rw-shop-ui .rw-shelf__all {
        height: 36px;
        padding: 0 16px;
        font-size: 14px;
    }

    .rw-shelf-card__body {
        padding: 14px 12px 16px 14px;
    }

    /* Verticales: sin sitio para la categoría (ya la dice el título de la fila); «Gratis» sí. */
    .rw-shelf-card--tall .rw-shelf-card__cat {
        display: none;
    }

    .rw-shelf-card--tall .rw-shelf-card__free::before {
        content: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rw-shelf-card__img,
    html body.rw-shop-ui .rw-shelf__arrow,
    html body.rw-shop-ui .rw-shelf__all {
        transition: none;
    }

    .rw-shelf-card:hover .rw-shelf-card__img {
        transform: none;
    }
}
