/*
 * Contenido enriquecido del editor HTML (bloques fx-*).
 * Se aplica igual en el editor (.rz-html-editor-content) y en la ficha pública (.fx-rich),
 * para que lo que se ve al editar sea lo que se publica.
 * Lo crea wwwroot/js/html-editor-images.js y lo anima wwwroot/js/rich-content.js.
 */

:is(.fx-rich, .rz-html-editor-content) {
    --fx-accent: #4f46e5;
    --fx-accent-soft: #eef2ff;
    --fx-radius: 14px;
    --fx-gap: 12px;
}

.fx-rich { display: flow-root; } /* contiene las imágenes flotadas */

:is(.fx-rich, .rz-html-editor-content) img {
    max-width: 100%;
    height: auto;
    box-sizing: border-box;
}

/* ───────── Pie de foto ───────── */
:is(.fx-rich, .rz-html-editor-content) figure.fx-figure {
    margin: 10px auto;
    max-width: 100%;
    box-sizing: border-box;
}

    :is(.fx-rich, .rz-html-editor-content) figure.fx-figure > img {
        display: block;
        width: 100%;
        margin: 0;
    }

    :is(.fx-rich, .rz-html-editor-content) figure.fx-figure > figcaption {
        margin-top: 6px;
        color: #6b7280;
        font-size: .85em;
        line-height: 1.4;
        text-align: center;
    }

/* ───────── Estilos de imagen ───────── */
:is(.fx-rich, .rz-html-editor-content) img[data-fx-style="rounded"] { border-radius: 16px; }

:is(.fx-rich, .rz-html-editor-content) img[data-fx-style="shadow"] {
    border-radius: 12px;
    box-shadow: 0 18px 40px -12px rgba(15, 23, 42, .35);
}

:is(.fx-rich, .rz-html-editor-content) img[data-fx-style="frame"] {
    padding: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, .08);
}

:is(.fx-rich, .rz-html-editor-content) img[data-fx-style="circle"] {
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 50%;
}

/* "Sin fondo": sombra que sigue la silueta del PNG transparente (renders 3D, recortes IA) */
:is(.fx-rich, .rz-html-editor-content) img[data-fx-style="cutout"] {
    filter: drop-shadow(0 16px 18px rgba(15, 23, 42, .28));
}

/* ───────── Galería ───────── */
:is(.fx-rich, .rz-html-editor-content) .fx-gallery {
    --cols: 3;
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--fx-gap);
    align-items: center;
    margin: 14px 0;
    clear: both;
}

:is(.fx-rich, .rz-html-editor-content) .fx-gallery[data-cols="2"] { --cols: 2; }
:is(.fx-rich, .rz-html-editor-content) .fx-gallery[data-cols="4"] { --cols: 4; }

:is(.fx-rich, .rz-html-editor-content) .fx-gallery img {
    display: block;
    width: 100%;
    margin: 0;
}

:is(.fx-rich, .rz-html-editor-content) .fx-gallery[data-equal="1"] img {
    height: 100%;
    aspect-ratio: 1 / 1;
    object-fit: contain;
}

    :is(.fx-rich, .rz-html-editor-content) .fx-gallery[data-equal="1"] img[data-fx-style="circle"] { object-fit: cover; }

/* Carrusel (solo en la ficha pública, una vez que rich-content.js lo ha montado) */
.fx-rich .fx-gallery[data-view="carousel"][data-fx-ready] {
    display: block;
}

.fx-rich .fx-car-track {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc((100% - var(--fx-gap) * (var(--cols) - 1)) / var(--cols));
    gap: var(--fx-gap);
    align-items: center;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
}

    .fx-rich .fx-car-track::-webkit-scrollbar { display: none; }
    .fx-rich .fx-car-track > img { scroll-snap-align: start; }

.fx-rich .fx-car-btn {
    position: absolute;
    top: calc(50% - 32px);
    z-index: 2;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 6px 18px rgba(15, 23, 42, .22);
    color: #111827;
    cursor: pointer;
    transition: opacity .2s, transform .2s;
}

    .fx-rich .fx-car-btn:hover { transform: scale(1.06); }
    .fx-rich .fx-car-btn[disabled] { opacity: 0; pointer-events: none; }
    .fx-rich .fx-car-btn.is-prev { left: 8px; }
    .fx-rich .fx-car-btn.is-next { right: 8px; }
    .fx-rich .fx-car-btn svg { width: 20px; height: 20px; }

.fx-rich .fx-car-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

    .fx-rich .fx-car-dots button {
        width: 8px;
        height: 8px;
        padding: 0;
        border: 0;
        border-radius: 999px;
        background: #d1d5db;
        cursor: pointer;
        transition: width .25s, background .25s;
    }

        .fx-rich .fx-car-dots button.is-active {
            width: 22px;
            background: var(--fx-accent);
        }

/* Lightbox: indicar que se puede ampliar */
.fx-rich img.fx-lb { cursor: zoom-in; }

/* ───────── Bloque Imagen + texto ───────── */
:is(.fx-rich, .rz-html-editor-content) .fx-media-text {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
    align-items: center;
    margin: 20px 0;
    clear: both;
}

:is(.fx-rich, .rz-html-editor-content) .fx-media-text[data-ratio="40"] { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
:is(.fx-rich, .rz-html-editor-content) .fx-media-text[data-side="right"][data-ratio="40"] { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
:is(.fx-rich, .rz-html-editor-content) .fx-media-text[data-side="right"] > .fx-mt-media { order: 2; }

:is(.fx-rich, .rz-html-editor-content) .fx-mt-media img {
    display: block;
    width: 100%;
    margin: 0;
}

:is(.fx-rich, .rz-html-editor-content) .fx-mt-body > :first-child { margin-top: 0; }
:is(.fx-rich, .rz-html-editor-content) .fx-mt-body > :last-child { margin-bottom: 0; }

:is(.fx-rich, .rz-html-editor-content) .fx-mt-placeholder {
    display: grid;
    place-items: center;
    aspect-ratio: 4 / 3;
    border: 2px dashed #c7d2fe;
    border-radius: var(--fx-radius);
    background: var(--fx-accent-soft);
    color: #4338ca;
    font-size: .85rem;
    font-weight: 600;
    text-align: center;
    cursor: pointer;
}

.fx-rich .fx-mt-placeholder { display: none; } /* nunca se publica un hueco vacío */

/* ───────── Avisos ───────── */
:is(.fx-rich, .rz-html-editor-content) .fx-callout {
    --c: #2563eb;
    --bg: #eff6ff;
    position: relative;
    margin: 16px 0;
    padding: 14px 16px 14px 50px;
    border: 1px solid color-mix(in srgb, var(--c) 22%, transparent);
    border-left: 4px solid var(--c);
    border-radius: 12px;
    background: var(--bg);
    clear: both;
}

    :is(.fx-rich, .rz-html-editor-content) .fx-callout::before {
        content: "";
        position: absolute;
        left: 16px;
        top: 15px;
        width: 22px;
        height: 22px;
        background: var(--c);
        -webkit-mask: var(--icon) center / contain no-repeat;
        mask: var(--icon) center / contain no-repeat;
    }

    :is(.fx-rich, .rz-html-editor-content) .fx-callout > :first-child { margin-top: 0; }
    :is(.fx-rich, .rz-html-editor-content) .fx-callout > :last-child { margin-bottom: 0; }

:is(.fx-rich, .rz-html-editor-content) .fx-callout[data-type="info"] {
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-1-11v6h2v-6h-2zm0-4v2h2V7h-2z'/%3E%3C/svg%3E");
}

:is(.fx-rich, .rz-html-editor-content) .fx-callout[data-type="warning"] {
    --c: #d97706;
    --bg: #fffbeb;
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12.866 3l9.526 16.5a1 1 0 0 1-.866 1.5H2.474a1 1 0 0 1-.866-1.5L11.134 3a1 1 0 0 1 1.732 0zM11 16v2h2v-2h-2zm0-7v5h2V9h-2z'/%3E%3C/svg%3E");
}

:is(.fx-rich, .rz-html-editor-content) .fx-callout[data-type="tip"] {
    --c: #7c3aed;
    --bg: #f5f3ff;
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9.973 18H11v-5h2v5h1.027c.132-1.202.745-2.194 1.74-3.277.113-.122.832-.867.917-.973a6 6 0 1 0-9.37-.002c.086.107.807.853.918.974.996 1.084 1.609 2.076 1.741 3.278zM10 20v1h4v-1h-4zm-4.246-5a8 8 0 1 1 12.49.002C17.624 15.774 16 17 16 18.5V21a2 2 0 0 1-2 2h-4a2 2 0 0 1-2-2v-2.5C8 17 6.375 15.774 5.754 15z'/%3E%3C/svg%3E");
}

:is(.fx-rich, .rz-html-editor-content) .fx-callout[data-type="success"] {
    --c: #059669;
    --bg: #ecfdf5;
    --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10-4.477 10-10 10zm-.997-6l7.07-7.071-1.414-1.414-5.656 5.657-2.829-2.829-1.414 1.414L11.003 16z'/%3E%3C/svg%3E");
}

/* ───────── Botón ───────── */
:is(.fx-rich, .rz-html-editor-content) .fx-btn-row {
    margin: 18px 0;
    text-align: center;
    clear: both;
}

:is(.fx-rich, .rz-html-editor-content) .fx-btn-row[data-align="left"] { text-align: left; }
:is(.fx-rich, .rz-html-editor-content) .fx-btn-row[data-align="right"] { text-align: right; }

:is(.fx-rich, .rz-html-editor-content) a.fx-btn {
    display: inline-flex;
    align-items: center;
    gap: .5em;
    padding: .8em 1.6em;
    border: 2px solid var(--fx-accent);
    border-radius: 999px;
    background: var(--fx-accent);
    color: #fff !important;
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none !important;
    box-shadow: 0 10px 24px -10px var(--fx-accent);
    transition: transform .2s, box-shadow .2s, background .2s;
}

    :is(.fx-rich, .rz-html-editor-content) a.fx-btn::after {
        content: "→";
        transition: transform .2s;
    }

    .fx-rich a.fx-btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 14px 28px -10px var(--fx-accent);
    }

        .fx-rich a.fx-btn:hover::after { transform: translateX(3px); }

    :is(.fx-rich, .rz-html-editor-content) a.fx-btn[data-variant="outline"] {
        background: transparent;
        color: var(--fx-accent) !important;
        box-shadow: none;
    }

/* ───────── Modelo 3D ───────── */
:is(.fx-rich, .rz-html-editor-content) .fx-3d {
    --ratio: 1 / 1;
    position: relative;
    width: 60%;
    max-width: 100%;
    margin: 18px auto;
    aspect-ratio: var(--ratio);
    overflow: hidden;
    border-radius: var(--fx-radius);
    background: radial-gradient(120% 120% at 50% 0%, #f8fafc 0%, #e2e8f0 100%);
    clear: both;
}

:is(.fx-rich, .rz-html-editor-content) .fx-3d[data-ratio="4/3"] { --ratio: 4 / 3; }
:is(.fx-rich, .rz-html-editor-content) .fx-3d[data-ratio="16/9"] { --ratio: 16 / 9; }

:is(.fx-rich, .rz-html-editor-content) .fx-3d-ph {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    color: #334155;
    font-size: .85rem;
    text-align: center;
}

    :is(.fx-rich, .rz-html-editor-content) .fx-3d-ph svg { width: 44px; height: 44px; color: var(--fx-accent); }
    :is(.fx-rich, .rz-html-editor-content) .fx-3d-ph strong { font-size: .95rem; }

:is(.fx-rich, .rz-html-editor-content) .fx-3d-preview {
    margin-top: 4px;
    padding: 6px 14px;
    border: 0;
    border-radius: 999px;
    background: var(--fx-accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

.fx-rich .fx-3d-preview { display: none; }

.fx-rich .fx-3d model-viewer,
.fx-3d-modal model-viewer {
    width: 100%;
    height: 100%;
    background: transparent;
    --poster-color: transparent;
}

.fx-rich .fx-3d-hint {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .6);
    color: #fff;
    font-size: .72rem;
    pointer-events: none;
    transition: opacity .4s;
}

.fx-rich .fx-3d.is-touched .fx-3d-hint { opacity: 0; }

/* ───────── Animaciones ───────── */
@keyframes fx-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

:is(.fx-rich, .rz-html-editor-content) [data-fx-anim="float"] {
    animation: fx-float 5s ease-in-out infinite;
}

.fx-rich [data-fx-anim]:not([data-fx-anim="float"]) {
    transition: opacity .8s ease, transform .8s cubic-bezier(.2, .7, .2, 1);
}

html.fx-js .fx-rich [data-fx-anim]:not([data-fx-anim="float"]):not(.is-in) { opacity: 0; }
html.fx-js .fx-rich [data-fx-anim="fade-up"]:not(.is-in) { transform: translateY(28px); }
html.fx-js .fx-rich [data-fx-anim="slide-left"]:not(.is-in) { transform: translateX(-48px); }
html.fx-js .fx-rich [data-fx-anim="slide-right"]:not(.is-in) { transform: translateX(48px); }
html.fx-js .fx-rich [data-fx-anim="zoom"]:not(.is-in) { transform: scale(.9); }

@media (prefers-reduced-motion: reduce) {
    :is(.fx-rich, .rz-html-editor-content) [data-fx-anim] {
        animation: none !important;
        transition: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
}

/* ───────── Móvil ───────── */
@media (max-width: 576px) {
    .fx-rich .fx-gallery[data-cols="3"],
    .fx-rich .fx-gallery[data-cols="4"] { --cols: 2; }

    .fx-rich .fx-gallery[data-view="carousel"] .fx-car-track { grid-auto-columns: 82%; }
    .fx-rich .fx-car-btn { display: none; }

    /* Las imágenes con texto alrededor pasan a ir centradas */
    .fx-rich img[style*="float"],
    .fx-rich figure.fx-figure[style*="float"] {
        float: none !important;
        display: block;
        margin: 10px auto !important;
        min-width: 60%;
    }

    .fx-rich .fx-media-text,
    .fx-rich .fx-media-text[data-ratio="40"],
    .fx-rich .fx-media-text[data-side="right"][data-ratio="40"] {
        grid-template-columns: minmax(0, 1fr);
        gap: 14px;
    }

    .fx-rich .fx-media-text[data-side="right"] > .fx-mt-media { order: 0; }
    .fx-rich .fx-3d { width: 100% !important; }
}
