/* Grilla (filas, columnas y sistema de 12 columnas) y contenido de las páginas GrapesJS. La cargan la página pública (Page.html.twig) y el lienzo del editor (PagesEditor.html.twig), cuyo <body> lleva las clases del contenedor. */

/* Filas GrapesJS: contenedores flex para columnas */
.grapesjs-native .gjs-row {
    display: flex !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    /* El relleno de la columna no se hereda a las columnas de una fila anidada */
    --rq-col-pad: initial;
}
/* Filas SIN altura fija: crecen con contenido (por defecto) */
.grapesjs-native .gjs-row:not(.has-fixed-height) {
    align-items: flex-start !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
}
/* Filas CON altura fija: contienen a sus hijos */
.grapesjs-native .gjs-row.has-fixed-height {
    align-items: stretch !important;
    overflow: hidden !important;
}
/* Alineación V de la fila (Centro y Abajo): solo aplica si la fila lo declara en línea. :is() toma la especificidad
   de un atributo, así que gana a las reglas forzadas de arriba. Sin espacio es como lo serializa GrapesJS. */
.grapesjs-native .gjs-row:is([style*="align-items:center"], [style*="align-items: center"]) {
    align-items: center !important;
}
.grapesjs-native .gjs-row:is([style*="align-items:flex-end"], [style*="align-items: flex-end"]) {
    align-items: flex-end !important;
}

/* Columnas GrapesJS */
.grapesjs-native .gjs-column {
    display: flex !important;
    flex-direction: column !important;
    min-height: 150px !important;
    height: auto !important;
    box-sizing: border-box !important;
    /* Piso de 4 px: con overflow-x: hidden, el anillo de foco de un botón o enlace pegado al borde quedaría cortado */
    padding: max(4px, var(--rq-col-pad, 8px)) !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
}

/* Columnas anidadas */
.grapesjs-native .gjs-column .gjs-column {
    min-height: 100px !important;
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
}
/* Filas anidadas */
.grapesjs-native .gjs-column .gjs-row {
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
}

/* Contexto de altura fija: descendientes contenidos */
.grapesjs-native .gjs-row.has-fixed-height .gjs-column {
    min-height: 0 !important;
    max-height: 100% !important;
    overflow: hidden !important;
}
.grapesjs-native .gjs-row.has-fixed-height .gjs-row {
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    align-items: stretch !important;
}

/* Contenedores genericos dentro de columnas */
.grapesjs-native .gjs-column > * {
    position: relative !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Responsive: liberar altura fija cuando las columnas se apilan o pasan a dos líneas (solo nativas) */
@media (max-width: 991px) {
    .grapesjs-native .gjs-row,
    .grapesjs-native .gjs-row.has-fixed-height,
    .grapesjs-native .gjs-row.has-fixed-height .gjs-row,
    .grapesjs-native .gjs-column .gjs-row {
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }
    .grapesjs-native .gjs-row.has-fixed-height .gjs-column,
    .grapesjs-native .gjs-column .gjs-column,
    .grapesjs-native .gjs-column {
        max-height: none !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
    }
}
/* «Ancho completo» sin escalar: con un contenedor bajo su mínimo de escalado, el script de Page.html.twig le pone
   `grapesjs-unscaled` y la página se reacomoda a su ancho real. Un alto fijo pensado para 1920 px de dibujo cortaría el contenido
   también entre 992 y 1279 px: valen las mismas liberaciones de altura que en el bloque de arriba (el apilado de columnas sigue sus
   propios cortes). El lienzo no lleva la clase: su Escritorio siempre está escalado, y Tablet y Móvil caen en el bloque de arriba. */
.grapesjs-full.grapesjs-unscaled .gjs-row,
.grapesjs-full.grapesjs-unscaled .gjs-row.has-fixed-height,
.grapesjs-full.grapesjs-unscaled .gjs-row.has-fixed-height .gjs-row,
.grapesjs-full.grapesjs-unscaled .gjs-column .gjs-row {
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}
.grapesjs-full.grapesjs-unscaled .gjs-row.has-fixed-height .gjs-column,
.grapesjs-full.grapesjs-unscaled .gjs-column .gjs-column,
.grapesjs-full.grapesjs-unscaled .gjs-column {
    max-height: none !important;
    overflow-x: hidden !important;
    overflow-y: visible !important;
}

/* Pública en móvil: las columnas apiladas miden lo que su contenido (también anula el min-height en línea que guarda el
   editor). Va con `div.` porque el lienzo lleva estas clases en su <body>, y ahí el alto mínimo sirve para soltar bloques. */
@media (max-width: 767.98px) {
    div.grapesjs-native .gjs-column,
    div.grapesjs-native .gjs-column .gjs-column {
        min-height: 0 !important;
    }
}

/* Filas genericas (.row de Bootstrap) */
.grapesjs-page-content .row {
    display: flex !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

/* Sistema de grid 12 columnas (Mobile-First) */
.grapesjs-page-content .col-12,
.grapesjs-page-content [class*="col-md-"],
.grapesjs-page-content [class*="col-lg-"] {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    width: 100% !important;
}

/* Ancho "Móvil" de la columna (`col-mobile`): con la misma especificidad que la base, le gana por venir después; md y lg vienen más abajo y siguen mandando en sus anchos. Solo aplica a columnas del editor (`:where` no suma especificidad): así no cambia el HTML propio ni las páginas migradas */
.grapesjs-page-content .col-1:where(.gjs-column) { flex: 0 0 8.333333% !important; max-width: 8.333333% !important; }
.grapesjs-page-content .col-2:where(.gjs-column) { flex: 0 0 16.666667% !important; max-width: 16.666667% !important; }
.grapesjs-page-content .col-3:where(.gjs-column) { flex: 0 0 25% !important; max-width: 25% !important; }
.grapesjs-page-content .col-4:where(.gjs-column) { flex: 0 0 33.333333% !important; max-width: 33.333333% !important; }
.grapesjs-page-content .col-5:where(.gjs-column) { flex: 0 0 41.666667% !important; max-width: 41.666667% !important; }
.grapesjs-page-content .col-6:where(.gjs-column) { flex: 0 0 50% !important; max-width: 50% !important; }
.grapesjs-page-content .col-7:where(.gjs-column) { flex: 0 0 58.333333% !important; max-width: 58.333333% !important; }
.grapesjs-page-content .col-8:where(.gjs-column) { flex: 0 0 66.666667% !important; max-width: 66.666667% !important; }
.grapesjs-page-content .col-9:where(.gjs-column) { flex: 0 0 75% !important; max-width: 75% !important; }
.grapesjs-page-content .col-10:where(.gjs-column) { flex: 0 0 83.333333% !important; max-width: 83.333333% !important; }
.grapesjs-page-content .col-11:where(.gjs-column) { flex: 0 0 91.666667% !important; max-width: 91.666667% !important; }

@media (min-width: 768px) {
    .grapesjs-page-content .col-md-1 { flex: 0 0 8.333333% !important; max-width: 8.333333% !important; }
    .grapesjs-page-content .col-md-2 { flex: 0 0 16.666667% !important; max-width: 16.666667% !important; }
    .grapesjs-page-content .col-md-3 { flex: 0 0 25% !important; max-width: 25% !important; }
    .grapesjs-page-content .col-md-4 { flex: 0 0 33.333333% !important; max-width: 33.333333% !important; }
    .grapesjs-page-content .col-md-5 { flex: 0 0 41.666667% !important; max-width: 41.666667% !important; }
    .grapesjs-page-content .col-md-6 { flex: 0 0 50% !important; max-width: 50% !important; }
    .grapesjs-page-content .col-md-7 { flex: 0 0 58.333333% !important; max-width: 58.333333% !important; }
    .grapesjs-page-content .col-md-8 { flex: 0 0 66.666667% !important; max-width: 66.666667% !important; }
    .grapesjs-page-content .col-md-9 { flex: 0 0 75% !important; max-width: 75% !important; }
    .grapesjs-page-content .col-md-10 { flex: 0 0 83.333333% !important; max-width: 83.333333% !important; }
    .grapesjs-page-content .col-md-11 { flex: 0 0 91.666667% !important; max-width: 91.666667% !important; }
    .grapesjs-page-content .col-md-12 { flex: 0 0 100% !important; max-width: 100% !important; }
}

@media (min-width: 992px) {
    .grapesjs-page-content .col-lg-1 { flex: 0 0 8.333333% !important; max-width: 8.333333% !important; }
    .grapesjs-page-content .col-lg-2 { flex: 0 0 16.666667% !important; max-width: 16.666667% !important; }
    .grapesjs-page-content .col-lg-3 { flex: 0 0 25% !important; max-width: 25% !important; }
    .grapesjs-page-content .col-lg-4 { flex: 0 0 33.333333% !important; max-width: 33.333333% !important; }
    .grapesjs-page-content .col-lg-5 { flex: 0 0 41.666667% !important; max-width: 41.666667% !important; }
    .grapesjs-page-content .col-lg-6 { flex: 0 0 50% !important; max-width: 50% !important; }
    .grapesjs-page-content .col-lg-7 { flex: 0 0 58.333333% !important; max-width: 58.333333% !important; }
    .grapesjs-page-content .col-lg-8 { flex: 0 0 66.666667% !important; max-width: 66.666667% !important; }
    .grapesjs-page-content .col-lg-9 { flex: 0 0 75% !important; max-width: 75% !important; }
    .grapesjs-page-content .col-lg-10 { flex: 0 0 83.333333% !important; max-width: 83.333333% !important; }
    .grapesjs-page-content .col-lg-11 { flex: 0 0 91.666667% !important; max-width: 91.666667% !important; }
    .grapesjs-page-content .col-lg-12 { flex: 0 0 100% !important; max-width: 100% !important; }
}

/* Centrar filas (justify-content) */
.grapesjs-page-content .row.justify-content-center,
.grapesjs-native .gjs-row.justify-content-center {
    justify-content: center !important;
}

/* «Ancho completo» (.grapesjs-full): las filas de primer nivel llevan un margen lateral para que el texto no toque el borde de
   la pantalla. En la pública cuelgan del escalador; en el lienzo, del wrapper de GrapesJS (un div dentro del <body>); en las
   miniaturas de la galería de plantillas, del <body> (su srcdoc no tiene wrapper). El relleno que la fila trae en línea o por
   id manda. */
.grapesjs-full > .grapesjs-page-scaler > .gjs-row,
body.grapesjs-full > [data-gjs-type="wrapper"] > .gjs-row,
body.grapesjs-full > .gjs-row {
    padding-inline: 1.5rem;
}
/* «Ancho completo»: un formulario incrustado se lee en columna, como en una página centrada: a lo más 1076 px (el ancho de
   dibujo de «Centrada») y al centro; en una columna más angosta ocupa la columna. Va después de `.gjs-column > *`, cuyo
   max-width lleva !important. width: 100% porque la columna es flex en columna y los márgenes auto lo encogerían a su contenido. */
.grapesjs-full .gjs-contact-form-placeholder {
    width: 100%;
    max-width: min(1076px, 100%) !important;
    margin-inline: auto;
}
/* Formulario de contacto publicado: `col-sm-6` de Bootstrap responde al ancho de la ventana, no al de la columna, así que en una
   columna angosta (1/3, 1/4) los campos seguían de a dos por fila y apretados. El bloque pasa a ser contenedor de consulta: sus
   medidas son las del dibujo (la página nativa se escala con transform), no las de la ventana. Con menos de 640 px cada campo
   ocupa la fila, la caja baja su relleno a 20 px (`!important` porque `.p30` también lo lleva) y el reCAPTCHA (304 px fijos) se
   reduce cuando ya no cabe. Solo con el `<form>` montado (pública): el lienzo también lleva `.grapesjs-page-content`, pero su caja no trae `<form>` y queda
   como antes (sin contención).
   width: 100% porque la contención hace que el ancho del bloque no dependa de su contenido: la columna es flex en columna y, con
   «Alineación H» Izquierda, Centro o Derecha (align-items en línea), el bloque se encoge a su contenido, que así mide 0. */
.grapesjs-page-content .gjs-contact-form-placeholder:has(form) {
    container-type: inline-size;
    width: 100%;
}
@container (max-width: 640px) {
    .grapesjs-page-content .gjs-contact-form-placeholder .form-question-answer[class*="col-"] {
        width: 100%;
        flex: 0 0 100%;
        max-width: 100%;
    }
    .grapesjs-page-content .gjs-contact-form-placeholder > .p30 {
        padding: 20px !important;
    }
}
@container (max-width: 343px) {
    .grapesjs-page-content .gjs-contact-form-placeholder .g-recaptcha {
        transform: scale(0.75);
        transform-origin: left top;
        margin-bottom: -20px;
    }
}
/* «Ancho completo»: el .container de Bootstrap que traen algunos bloques (Video + Texto, Imagen + Texto, Tarjeta, …) toma su tope del
   ancho real de la ventana, pero la página se dibuja a 1920 px, donde el lienzo le da 1320. Con la página escalada (contenedor desde
   1280 px, el mínimo de escalado) el tope es el del dibujo; si no, entre 1280 y 1399 px Bootstrap le daría 1140. Bajo 1280 la página
   se reacomoda y rigen los topes de Bootstrap. Las reglas de las secciones (page-sections.css, más específicas) siguen mandando. */
@media (min-width: 1280px) {
    .grapesjs-full .container {
        max-width: 1320px;
    }
}

/* ========== CONTENIDO (nativas y migradas) ========== */

/* Enlaces dentro de un texto: subrayados (el color solo no basta, WCAG 1.4.1). Sin botones, .text-decoration-none ni títulos, tampoco dentro de una lista; le gana a main.css. */
.grapesjs-page-content :is(p, li) a:not(.btn, .text-decoration-none, :is(h1, h2, h3, h4, h5, h6) a) {
    text-decoration: underline !important;
}

/* Texto: evitar desbordamiento horizontal */
.grapesjs-page-content :is(p, h1, h2, h3, h4, h5, h6, span, a, li, td, th, label) {
    overflow-wrap: anywhere !important;
    word-wrap: break-word !important;
    word-break: break-word !important;
    max-width: 100% !important;
}

/* Botones */
.grapesjs-page-content .btn,
.grapesjs-page-content a.btn,
.grapesjs-page-content button {
    max-width: 100% !important;
    white-space: normal !important;
    overflow-wrap: break-word !important;
}

/* Imagenes, videos e iframes: responsivos */
.grapesjs-page-content :is(img, svg, video, iframe, embed, object, canvas) {
    max-width: 100% !important;
    display: block;
}
.grapesjs-page-content img:where(:not([style*="object-fit"])),
.grapesjs-page-content svg {
    height: auto !important;
}

/* Componente video: aspect ratio */
.grapesjs-page-content .video-embed-wrapper {
    display: block !important;
    max-width: 100% !important;
    min-width: 150px !important;
    height: auto !important;
    box-sizing: border-box !important;
    overflow: visible !important;
}
.grapesjs-page-content .video-ratio-wrapper,
.grapesjs-page-content .video-placeholder-wrapper {
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    overflow: hidden !important;
}
.grapesjs-page-content .video-ratio-wrapper iframe,
.grapesjs-page-content .video-placeholder-content {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
    border: none !important;
}

/* Tablas */
.grapesjs-page-content table {
    max-width: 100% !important;
    width: 100% !important;
    table-layout: fixed !important;
    overflow-wrap: break-word !important;
}

/* Pre y code */
.grapesjs-page-content :is(pre, code) {
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    max-width: 100% !important;
    overflow-x: auto !important;
}
