/* --- IMPORT DEI FONT E STILI GLOBALI --- */
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Montserrat:wght@400;700&family=Open+Sans:wght@400;700&family=Oswald:wght@400;700&family=Roboto:wght@400;700&display=swap');

:root {
    --primary-color: #007bff;
    --primary-hover-color: #0056b3;
    --danger-color: #dc3545;
    --danger-hover-color: #c82333;
    --danger-color-rgb: 220, 53, 69;
    --danger-hover-color-rgb: 200, 35, 51;
    
    --background-color: #f4f7f9;
    --editor-background-color: #ffffff;
    --border-color: #dee2e6;
    --text-color: #333;
    --light-text-color: #6c757d;
    --white-color: #ffffff;
    --block-shadow: 0 2px 5px rgba(0,0,0,0.05);

    --header-height: 60px;
    --controls-height: 60px;
}
#editor-canvas {
    background-color: #ffffff !important;
    min-height: 800px;
    padding: 20px;
    box-sizing: border-box;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s;
}

.lanewsletter-container {
    display: flex;
    height: 100vh;
    padding-top: 60px;
}

/* --- HEADER --- */
.lanewsletter-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--white-color);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.lanewsletter-header h1 {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.lanewsletter-global-controls,
.lanewsletter-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.lanewsletter-global-controls label,
.lanewsletter-global-controls select,
.lanewsletter-global-controls input[type="color"] {
    font-size: 0.9rem;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.lanewsletter-global-controls input[type="color"] {
    padding: 2px;
    height: 32px;
    width: 40px;
    cursor: pointer;
}

/* --- PULSANTI GENERICI --- */
.lanewsletter-btn {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    transition: background-color 0.2s;
    color: var(--white-color);
}

.lanewsletter-btn-primary {
    background-color: var(--primary-color);
}
.lanewsletter-btn-primary:hover {
    background-color: var(--primary-hover-color);
}

.lanewsletter-btn-secondary {
    background-color: #6c757d;
}
.lanewsletter-btn-secondary:hover {
    background-color: #5a6268;
}

.lanewsletter-btn-danger {
    background-color: var(--danger-color);
}
.lanewsletter-btn-danger:hover {
    background-color: var(--danger-hover-color);
}


/* --- PANNELLO SINISTRO (PALETTE BLOCCHI) --- */
.lanewsletter-sidebar {
    width: 250px;
    flex-shrink: 0;
    background-color: var(--white-color);
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
}

.lanewsletter-sidebar h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.lanewsletter-block-palette ul {
    list-style: none;
    padding: 0;
}

.lanewsletter-block-palette li button {
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background-color: var(--background-color);
    border: 1px dashed var(--border-color);
    border-radius: 4px;
    text-align: left;
    font-size: 0.9rem;
    cursor: grab;
    transition: background-color 0.2s, border-color 0.2s;
}

.lanewsletter-block-palette li button:hover {
    background-color: var(--primary-color);
    color: var(--white-color);
    border-color: var(--primary-hover-color);
}


/* --- AREA CENTRALE (EDITOR CANVAS) --- */
.lanewsletter-main {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
}

#editor-canvas {
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--editor-background-color);
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    min-height: 100%;
}

.lanewsletter-editor-placeholder-message {
    text-align: center;
    color: var(--light-text-color);
    padding: 50px 20px;
    font-size: 1.2rem;
    border: 2px dashed var(--border-color);
    border-radius: 5px;
}

/* --- STILI PER I SINGOLI BLOCCHI NELL'EDITOR --- */
.lanewsletter-block {
    border: 1px solid var(--border-color);
    background-color: var(--white-color);
    margin-bottom: 20px;
    border-radius: 4px;
    box-shadow: var(--block-shadow);
    transition: box-shadow 0.2s, border-color 0.2s;
}

.lanewsletter-block:hover {
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border-color: var(--primary-color);
}

/* Intestazione del blocco */
.amdweb-block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: #f7f9fc;
    border-bottom: 1px solid var(--border-color);
}

.amdweb-block-header h2 {
    font-size: 0.9rem;
    color: var(--text-color);
    font-weight: bold;
    margin: 0;
}

.amdweb-block-controls {
    display: flex;
    gap: 5px;
}

.amdweb-block-controls button {
    background: #e9ecef;
    border: 1px solid #ced4da;
    border-radius: 3px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #495057;
    transition: background-color 0.2s, color 0.2s;
}

.amdweb-block-controls button:hover {
    background: var(--primary-color);
    color: var(--white-color);
}

.amdweb-block-content {
    padding: 20px;
}

/* Placeholders e aree editabili */
.amdweb-image-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    background-color: #f9f9f9;
    border: 2px dashed var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    color: var(--light-text-color);
    transition: border-color 0.2s, background-color 0.2s;
}
.amdweb-image-placeholder:hover {
    border-color: var(--primary-color);
}
.amdweb-image-placeholder img {
    max-width: 100%;
    height: auto;
    display: block;
}


/* --- QUILL EDITOR STYLES --- */
.amdweb-text-editor-container {
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
.amdweb-block-quill-toolbar {
    background-color: #f7f7f7;
    border-bottom: 1px solid var(--border-color);
    padding: 5px;
}
.amdweb-block-quill-editor {
    min-height: 150px;
    font-size: 16px;
}
.small-editor {
    min-height: 100px;
}


/* --- MODALI --- */
/* Stili base delle modali */
.amdweb-modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
}

.amdweb-modal-content { 
    background-color: var(--white-color);
    margin: auto;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    min-width: 300px; 
    max-width: 500px;
    width: 90%;
    max-height: 95vh;

    display: flex;
    flex-direction: column;
}

.amdweb-modal-close-btn {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s ease;
}
.amdweb-modal-close-btn:hover,
.amdweb-modal-close-btn:focus {
    color: #333;
    text-decoration: none;
}

.amdweb-modal-header {
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    text-align: center;
}
.amdweb-modal-header h2 {
    margin: 0;
    font-size: 1.6rem;
    color: var(--text-color);
}

.amdweb-modal-body {
    padding: 0;
    flex-grow: 1;
    overflow-y: auto;
    padding-right: 15px;
}

.amdweb-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    
    position: sticky;
    bottom: 0;
    background-color: var(--white-color);
    width: 100%;
    left: 0;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.03);
    z-index: 10; 
}


/* --- MIGLIORAMENTI SPECIFICI PER CONTENUTI DELLE MODALI --- */

/* Contenuto della modale di anteprima */
#previewModalContent { 
    padding: 25px;
}

/* Stili per la modalità a tutta pagina della modale di anteprima */
#previewModal.fullscreen #previewModalContent {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0;
    padding: 0;
}

/* Regola il header e i controlli per la modalità fullscreen */
#previewModal.fullscreen .amdweb-modal-header,
#previewModal.fullscreen .lanewsletter-preview-controls {
    padding: 10px 20px;
}

.lanewsletter-preview-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.lanewsletter-preview-controls button {
    background-color: #e9ecef;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.lanewsletter-preview-controls button.active {
    background-color: var(--primary-color);
    color: var(--white-color);
    border-color: var(--primary-hover-color);
}

/* L'iframe della preview occupa il 100% del suo genitore */
#previewIframe {
    flex-grow: 1;
    border: 1px solid var(--border-color);
    background-color: var(--white-color);
    margin: 0 auto;
    width: 100%;
    height: 100%;
    max-width: none;
    min-width: 0;
    min-height: 0;
}

/* Stili per i campi del form nelle modali generiche */
.amdweb-modal-field {
    margin-bottom: 15px;
}

.amdweb-modal-field label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: var(--text-color);
    font-size: 0.95rem;
}

.amdweb-modal-field input[type="text"],
.amdweb-modal-field input[type="number"],
.amdweb-modal-field select,
.amdweb-modal-field textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-sizing: border-box;
    font-size: 0.95rem;
    color: var(--text-color);
    background-color: var(--white-color);
}

/* Stile specifico per l'input di tipo colore */
.amdweb-modal-field input[type="color"] {
    width: 60px;
    height: 35px;
    border: 1px solid var(--border-color);
    padding: 2px;
    cursor: pointer;
    border-radius: 4px;
}

/* Stile per i bottoni all'interno dei campi modali */
.amdweb-modal-field button.lanewsletter-btn {
    margin-top: 5px;
    display: block;
    width: 100%;
    text-align: center;
}

/* Stile per il messaggio di errore nella modale generica */
#generic-modal-error-message {
    color: var(--danger-color);
    margin-bottom: 10px;
    text-align: center;
    font-weight: bold;
    font-size: 0.9em;
}

/* Stili per la barra di scorrimento nelle modali con overflow */
.amdweb-modal-body::-webkit-scrollbar {
  width: 8px;
}

.amdweb-modal-body::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.amdweb-modal-body::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 10px;
}

.amdweb-modal-body::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Stili per il contenitore di anteprima nelle modali di configurazione */
#modal-preview-container {
    background-color: #f9f9f9;
    border: 1px dashed var(--primary-color);
    border-radius: 5px;
    padding: 15px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    font-size: 0.9em;
    color: var(--light-text-color);
    text-align: center;
    overflow: hidden;
}

/* Stili per il bottone di anteprima nelle modali di configurazione */
#modal-preview-button {
    font-family: inherit;
    cursor: default;
}

/* Stili per l'immagine di anteprima del logo nella modale di configurazione */
#modal-preview-logo-image {
    max-width: 100%;
    height: auto;
}

/* Responsive styles */
.responsive-column {
    width: auto !important; 
    display: table-cell !important; /* Default desktop */
    box-sizing: border-box;
    vertical-align: top; 
}
table.responsive-table {
    mso-table-lspace: 0pt;
    mso-table-rspace: 0pt;
}


@media screen and (max-width: 480px) {
    .email-container {
        width: 100% !important; 
        max-width: 100% !important;
    }
    /* Regole per le colonne responsive */
    .responsive-column {
        width: 100% !important; 
        max-width: 100% !important;
        display: block !important; /* Forza l'impilamento verticale */
        float: none !important; /* Rimuove i float per l'impilamento */
        text-align: center !important;
        padding: 10px !important; /* Padding per mobile */
        box-sizing: border-box !important; 
    }
    /* Assicurati che le tabelle figlie dirette delle colonne responsive si comportino come blocco */
    .responsive-column > table { 
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
        margin-bottom: 10px !important; /* Spazio tra colonne impilate */
        float: none !important;
        text-align: center !important;
    }
    /* Regola specifica per la responsive table esterna che contiene le colonne */
    table.responsive-table { 
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
        margin-bottom: 10px !important;
        float: none !important;
        text-align: center !important;
    }
    table.responsive-table.last { 
        margin-bottom: 0 !important;
    }
    .responsive-column img {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 0 auto !important;
    }

    /* Hack aggiuntivo per forzare il display block su td e tr se necessario */
    .responsive-column td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
    .responsive-column tr {
        display: block !important;
        width: 100% !important;
    }
    /* Altri hack se i margini non sono corretti */
    .responsive-column + .responsive-column {
        margin-top: 20px !important; /* Spazio tra le colonne impilate */
    }
    /* Hack per eliminare spazi indesiderati causati da font-size: 0 */
    td[align="center"][style*="font-size: 0"] {
        line-height: 1px !important;
    }
    /* NUOVE REGOLE AGGIUNTIVE PER I CONTENITORI INTERNI ALLE COLONNE */
    .responsive-column .content-wrapper {
        width: 100% !important;
        display: block !important;
        text-align: center !important; /* Forza il testo a centrare anche se il blocco si espande */
        margin: 0 !important; /* Assicurati che non ci siano margini esterni indesiderati */
        padding: 0 !important; /* Assicurati che non ci siano padding esterni indesiderati */
    }
    .responsive-column .ql-editor-content {
        width: 100% !important;
        display: block !important;
        text-align: inherit !important; /* Mantiene l'allineamento specifico del testo di Quill */
        margin: 0 !important;
        padding: 0 !important;
        min-height: 0 !important; /* Evita altezze minime fisse che possono creare spazio bianco */
    }
    /* Regola per i paragrafi all'interno del contenuto di Quill per evitare margini doppi */
    .responsive-column .ql-editor-content p {
        margin: 0 !important;
        padding: 0 !important;
    }
    .responsive-column .ql-editor-content p + p {
        margin-top: 1em !important; /* Riapplica un margine tra paragrafi */
    }
}