/* richEditor.css - Toolbar e area di scrittura per il nuovo editor di testo
   ricco condiviso (richEditor.js, sostituto di TinyMCE), riusa le variabili
   colore/bordo gia' definite in app.css per restare coerente col resto
   dell'interfaccia. */

.gsrte-wrap {
    border: 1px solid var(--border-strong);
    border-radius: 0.5rem;
    overflow: hidden;
    background: var(--surface);
}

.gsrte-wrap.gsrte-fullscreen {
    position: fixed;
    inset: 0.75rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.gsrte-wrap.gsrte-fullscreen .gsrte-content {
    flex: 1;
    height: auto !important;
}

.gsrte-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.1rem;
    padding: 0.35rem;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border-strong);
}

/* Promemoria sotto ogni istanza dell'editor: il testo fra parentesi non
   viene letto dal lettore automatico (accessibility.js "Leggi la pagina",
   flashcard_study.js "Leggi la carta") — senza questo avviso la regola
   sarebbe invisibile finché qualcuno non la scopre per caso ascoltando una
   lettura con un pezzo mancante. */
.gsrte-hint {
    padding: 0.35rem 0.6rem;
    font-size: 0.72rem;
    color: var(--text-muted, var(--text-body));
    background: var(--surface-alt);
    border-top: 1px solid var(--border-strong);
}

.gsrte-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 0.35rem;
    background: transparent;
    color: var(--text-body);
    cursor: pointer;
}

.gsrte-btn svg { width: 17px; height: 17px; }

.gsrte-btn:hover { background: var(--surface); }

.gsrte-btn[data-active="true"] {
    background: var(--teal-600);
    color: var(--white);
}

.gsrte-sep {
    width: 1px;
    align-self: stretch;
    margin: 0.2rem 0.3rem;
    background: var(--border-strong);
}

.gsrte-dropdown-btn {
    width: auto;
    min-width: 4.4rem;
    height: 28px;
    padding: 0 0.4rem;
    gap: 0.3rem;
    font-size: 0.8rem;
    justify-content: space-between;
}

.gsrte-dropdown-btn-size { min-width: 3rem; }

.gsrte-dropdown-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gsrte-dropdown-btn::after {
    content: '';
    flex: none;
    width: 0;
    height: 0;
    margin-left: 0.1rem;
    border-left: 3px solid transparent;
    border-right: 3px solid transparent;
    border-top: 4px solid currentColor;
    opacity: 0.55;
}

.gsrte-dropdown-popover {
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    min-width: 8.5rem;
    max-height: 16rem;
    overflow-y: auto;
}

.gsrte-dropdown-item {
    border: none;
    background: transparent;
    text-align: left;
    padding: 0.4rem 0.55rem;
    border-radius: 0.3rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-body);
}

.gsrte-dropdown-item:hover { background: var(--surface-alt); }
.gsrte-dropdown-item[data-active="true"] { background: var(--teal-600); color: var(--white); }

.gsrte-color-input {
    width: 28px;
    height: 28px;
    padding: 2px;
    border: 1px solid var(--border-strong);
    border-radius: 0.35rem;
    background: var(--surface);
    cursor: pointer;
}

.gsrte-content {
    padding: 0.75rem;
    overflow-y: auto;
    min-height: 120px;
    resize: vertical;   /* l'area di scrittura si ingrandisce trascinando l'angolo in basso a destra */
}

.gsrte-editable {
    outline: none;
    min-height: 100%;
    line-height: 1.5;
}

.gsrte-editable p { margin: 0 0 0.6em; }
.gsrte-editable p:last-child { margin-bottom: 0; }
.gsrte-editable ul, .gsrte-editable ol { margin: 0 0 0.6em; padding-left: 1.4em; }
.gsrte-editable li::marker { color: inherit; }
.gsrte-editable img { max-width: 100%; height: auto; }
.gsrte-editable a { color: var(--teal-700); }
.gsrte-editable hr { border: none; border-top: 1px solid var(--border-strong); margin: 0.8em 0; }

.gsrte-popover {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 0.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    padding: 0.5rem;
    z-index: 1100;
}

.gsrte-charmap {
    display: grid;
    grid-template-columns: repeat(8, 2.1rem);
    gap: 0.2rem;
}

.gsrte-charmap button {
    border: none;
    background: transparent;
    border-radius: 0.3rem;
    font-size: 1.15rem;
    padding: 0.4rem 0;
    cursor: pointer;
}

.gsrte-charmap button:hover { background: var(--surface-alt); }

.gsrte-color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1.5rem);
    gap: 0.3rem;
    margin-bottom: 0.5rem;
}

.gsrte-swatch {
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.3rem;
    padding: 0;
    cursor: pointer;
}

/* Niente transform:scale() sull'hover — su elementi così piccoli il
   ridimensionamento via GPU compositing li rende visibilmente sfocati
   invece di un semplice ingrandimento nitido. Un outline non tocca il
   rendering del quadratino stesso. */
.gsrte-swatch:hover { outline: 2px solid var(--teal-600); outline-offset: 1px; }

.gsrte-color-hex-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border-top: 1px solid var(--border-strong);
    padding-top: 0.5rem;
}

.gsrte-btn[data-disabled="true"] { opacity: 0.35; pointer-events: none; }

.gsrte-table-picker-label {
    font-size: 0.75rem;
    color: var(--text-muted, var(--text-body));
    text-align: center;
    margin-bottom: 0.35rem;
}

.gsrte-table-grid {
    display: grid;
    grid-template-columns: repeat(6, 1.1rem);
    grid-template-rows: repeat(6, 1.1rem);
    gap: 0.15rem;
}

.gsrte-table-grid button {
    width: 1.1rem;
    height: 1.1rem;
    padding: 0;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 0.15rem;
    cursor: pointer;
}

.gsrte-table-grid button.gsrte-table-grid-on {
    background: var(--teal-600);
    border-color: var(--teal-600);
}

.gsrte-table-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.2rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-strong);
}

.gsrte-table-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 0.35rem;
    background: transparent;
    color: var(--text-body);
    cursor: pointer;
}

.gsrte-table-actions button svg { width: 16px; height: 16px; }
.gsrte-table-actions button:hover { background: var(--surface-alt); }
.gsrte-table-actions button[data-disabled="true"] { opacity: 0.35; pointer-events: none; }

.gsrte-align-popover {
    display: flex;
    gap: 0.1rem;
}

.gsrte-align-popover button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 0.35rem;
    background: transparent;
    color: var(--text-body);
    cursor: pointer;
}

.gsrte-align-popover button svg { width: 17px; height: 17px; }
.gsrte-align-popover button:hover { background: var(--surface-alt); }
.gsrte-align-popover button[data-active="true"] { background: var(--teal-600); color: var(--white); }

.gsrte-menu-popover {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 13rem;
}

.gsrte-menu-item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    border: none;
    background: transparent;
    padding: 0.45rem 0.5rem;
    border-radius: 0.35rem;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-body);
    text-align: left;
}

.gsrte-menu-item svg { width: 17px; height: 17px; flex: none; }
.gsrte-menu-item:hover { background: var(--surface-alt); }

/* L'export legge solo lo style page-break-after inline (vedi
   richEditorExtensions.js), questo blocco serve solo a rendere visibile e
   selezionabile l'interruzione mentre si scrive. */
.gsrte-editable .page-break {
    position: relative;
    height: 0;
    margin: 1.4em 0;
    border-top: 2px dashed var(--border-strong);
}

.gsrte-editable .page-break::after {
    content: 'Interruzione di pagina';
    position: absolute;
    top: -0.6em;
    left: 0.75em;
    background: var(--surface);
    padding: 0 0.4em;
    font-size: 0.7rem;
    color: var(--text-muted, var(--text-body));
}

.gsrte-editable table {
    border-collapse: collapse;
    width: 100%;
    margin: 0 0 0.6em;
}

.gsrte-editable td.gsrte-td {
    border: 2px solid var(--border-strong);
    padding: 0.4em 0.6em;
    vertical-align: top;
    min-width: 2em;
}

.gsrte-editable table.gsrte-table-borderless td.gsrte-td {
    border-color: transparent;
}

.gsrte-editable td.gsrte-td p { margin: 0; }

.gsrte-editable img.ProseMirror-selectednode {
    outline: 2px solid var(--teal-600);
    outline-offset: 2px;
}

.gsrte-img-resize-handle {
    display: none;
    position: fixed;
    /* 32px: area di TRASCINAMENTO (invisibile, solo per il mousedown), non
       il pallino visibile — quello resta piccolo (::after sotto) per non
       coprire l'angolo dell'immagine, ma il bersaglio cliccabile è molto più
       ampio. Un pallino di 20px "pieno" era già stato provato e segnalato
       di nuovo come troppo piccolo da colpire con precisione (segnalato più
       volte come "il ridimensionamento non funziona" quando in realtà il
       trascinamento mancava il pallino) — vedi anche lo scostamento in
       reposition(), aggiornato in coppia con questa dimensione. */
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    cursor: nwse-resize;
    z-index: 1100;
}
.gsrte-img-resize-handle::after {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--teal-600);
    border: 2px solid var(--white);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.gsrte-img-align-bar {
    display: none;
    position: fixed;
    gap: 0.1rem;
    padding: 0.2rem;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 0.4rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
    z-index: 1100;
}

.gsrte-img-align-bar button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: none;
    border-radius: 0.3rem;
    background: transparent;
    color: var(--text-body);
    cursor: pointer;
}

.gsrte-img-align-bar .gsrte-img-pct { width: auto; padding: 0 6px; font-size: 12px; font-weight: 600; }
.gsrte-img-align-bar button svg { width: 15px; height: 15px; }
.gsrte-img-align-bar button:hover { background: var(--surface-alt); }

.gsrte-color-hex {
    flex: 1;
    min-width: 0;
    height: 28px;
    border: 1px solid var(--border-strong);
    border-radius: 0.35rem;
    background: var(--surface);
    color: var(--text-body);
    font-size: 0.8rem;
    padding: 0 0.4rem;
}


/* Finestra «Inserisci link» con l'elenco degli ultimi file allegati. */
.gsrte-link-overlay { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.4); }
.gsrte-link-dialog { width: min(480px, 100%); max-height: 90vh; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: 14px; background: var(--surface, #fff); color: var(--text, #111); box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3); }
.gsrte-link-input { width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong, #cbd5e1); border-radius: 8px; font: inherit; background: var(--surface, #fff); color: inherit; box-sizing: border-box; }
.gsrte-link-label { font-size: 0.8rem; font-weight: 600; opacity: 0.7; }
.gsrte-link-recent { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; }
.gsrte-link-recent button { width: 100%; text-align: left; padding: 7px 10px; border: 1px solid var(--border-strong, #cbd5e1); border-radius: 8px; background: transparent; color: inherit; font: inherit; font-size: 0.9rem; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gsrte-link-recent button:hover { background: var(--surface-alt, #f1f5f9); }
.gsrte-link-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.gsrte-link-actions button { padding: 7px 14px; border: 1px solid var(--border-strong, #cbd5e1); border-radius: 8px; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.gsrte-link-actions .gsrte-link-ok { background: var(--color-primary, #1fb5b4); border-color: transparent; color: #fff; font-weight: 600; }
