/* Utility per il loader */


.loader {
    --loader-size: clamp(40px, 5vw, 60px);
    --border-width: clamp(4px, 0.5vw, 8px);

    border: var(--border-width) solid #f3f3f3;
    border-top: var(--border-width) solid #3498db;
    border-radius: 50%;
    width: var(--loader-size);
    height: var(--loader-size);
    animation: spin 2s linear infinite;
    display: none;
    margin: clamp(10px, 2vh, 30px) auto;
}


.custom-text-editor p {
    margin-block-end: .3rem;
}

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

/* Layout del form */
.full-width-form {
    display: grid;
    width: min(100%, 1200px);
    margin-inline: auto;
    gap: 1rem;
}

.full-width-form input[type="submit"] {
    justify-self: center;
}

/* Container principale dell'editor - rimosso padding e limitazione larghezza */
.text-editor-container {
    position: relative;
    width: 100%;
    margin-inline: auto;
}

.text-editor-background {
    position: relative;
    /* aspect-ratio will be set dynamically by JS based on image */
    width: 100%;
    height: auto;
    max-height: 80vh; /* Ensure max-height is always respected */
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    overflow: hidden;
    margin-inline: auto;
    /* Smooth transitions for resize */
    transition: width 0.2s ease, height 0.2s ease;
    
    /* Container query support for modern browsers */
    container-type: size;
    
    /* CSS custom properties for dynamic sizing */
    --max-font-size: 18px;
    --min-font-size: 8px;
    --line-height-ratio: 1.2;
    
    /* Force proper containment */
    contain: layout style;
}

/* When viewport is narrower, adjust the container behavior */
@media screen and (max-width: 1024px) {
    .text-editor-background {
        /* In single column, prioritize height constraint */
        max-height: 70vh;
        width: auto;
        max-width: 100%;
    }
}

.custom-text-editor {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    color: #000;
    resize: none;
    box-sizing: border-box;
    outline: none;
    overflow: visible;
    font-family: var(--e-global-typography-text-font-family), Sans-serif;
    font-weight: var(--e-global-typography-text-font-weight);

    display: flex;
    flex-direction: column;
    justify-content: center; /* Centra verticalmente */

    /* Font size calcolato responsivamente da JavaScript */
    font-size: 16px;
    line-height: 1.2;
    
    /* Transizione fluida per il font-size */
    transition: font-size 0.15s ease;
}

/* Fallback for browsers without container queries */
@supports not (font-size: 100cqw) {
    .custom-text-editor {
        font-size: clamp(
            var(--min-font-size, 8px),
            min(4vw, 3vh, var(--max-font-size, 18px)),
            var(--max-font-size, 18px)
        );
    }
}

/* Nasconde il testo durante il caricamento dell'immagine di sfondo */
.custom-text-editor.loading {
    visibility: hidden;
}

.editor-toolbar {
    --toolbar-padding: clamp(5px, 1vw, 10px);

    position: absolute;
    background: #fff;
    border: 1px solid #ccc;
    padding: var(--toolbar-padding);
    display: none;
    z-index: 1000;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.editor-toolbar button {
    --button-size: clamp(24px, 3vw, 32px);

    background: none;
    border: none;
    cursor: pointer;
    font-size: clamp(14px, 1.5vw, 16px);
    margin: 0 2px;
    padding: calc(var(--button-size) / 8);
    transition: background-color 0.2s ease;
}

.editor-toolbar button:hover {
    background: #f0f0f0;
}

/* Grid system moderno - CSS Grid responsivo che funziona già di default */
.flex-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); /* usa 1fr per espansione fluida */
    gap: max(20px, 2vw); /* gap minimo con max() */
    width: 90%;
    margin: auto;
    max-width: calc(5 * 450px + 4 * max(20px, 2vw)); /* Limita a massimo 5 colonne */
    justify-content: start; /* Allinea a sinistra */
}

/* Sistema parametrico: simula elementi fake per mantenere sempre 5 colonne totali */

/* 1 elemento reale → crea 4 fake (span 4) */
.flex-container:has(.flex-item:first-child:nth-last-child(1))::after {
    content: '';
    grid-column: span 4;
}

/* 2 elementi reali → crea 3 fake (span 3) */
.flex-container:has(.flex-item:first-child:nth-last-child(2))::after {
    content: '';
    grid-column: span 3;
}

/* 3 elementi reali → crea 2 fake (span 2) */
.flex-container:has(.flex-item:first-child:nth-last-child(3))::after {
    content: '';
    grid-column: span 2;
}

/* 4 elementi reali → crea 1 fake (span 1) */
.flex-container:has(.flex-item:first-child:nth-last-child(4))::after {
    content: '';
    grid-column: span 1;
}

/* 5+ elementi reali → non crea niente */
.flex-container:has(.flex-item:first-child:nth-last-child(n+5))::after {
    content: none; /* Disabilita il pseudo-elemento */
}

.flex-item {
    margin: 0;
    margin-bottom: 25px;
    /* Prevent overflow in single column */
    max-width: 100%;
    overflow: hidden;
}

/* Single column layout - center alignment and prevent overflow */
@media screen and (max-width: 768px) {
    .flex-container {
        justify-content: center; /* Centra in visualizzazione mobile */
    }

    .flex-item .text-editor-background {
        max-height: 60vh; /* Reduce height in mobile */
        width: 100%;
    }

    .flex-container::after {
        content: none !important;
        display: none !important;
    }

}

/* Divider che deve occupare tutta la larghezza del container */
.flex-container .col-12 {
    grid-column: 1 / -1; /* Occupa tutte le colonne disponibili */
    width: 90%;
    margin: 0 auto;
}

/* Container manifesti - la dimensione e allineamento sono gestiti da .flex-container */


