﻿/** SMART - FORM PRINCIPI BASE
 * 
Per mettere in ordine i controlli in una pagina dividiamo la larghezza disponibile in colonne variabili a seconda della dimensione dello schermo.

Ogni controllo occupa un numero di colonne sufficiente a mostrare bene:

- la label
    - il contenuto
        - eventuali pulsanti o addon collegati

L’obiettivo è usare lo spazio nel modo più efficiente possibile mantenendo la pagina ordinata, leggibile e compatta.


    REGOLA 15 - BREAKPOINT COLONNE

XL = 12 colonne
LG = 8 colonne
MD = 6 colonne
SM = 4 colonne
XSM = 3 colonne


ALTRE REGOLE

1. Usare meno classi possibile.
   Classe contenitore principale:
smart - form / smart - form - simple

2. Ogni campo usa:
sf - item

3. Attributi disponibili:
data - label
data - span
data - auto - span
data - fixed - span

4. data - span =
   numero fisso di colonne occupate.

5. data - auto - span =
   calcolo automatico colonne necessarie in base a:
- label
    - contenuto
    - tipo controllo
        - spazio residuo riga

6. data - fixed - span =
   priorità assoluta.Nessun ricalcolo.

7. I campi brevi restano piccoli.
    Esempi:
Numero
Tipo
Data
Porto
Stato

8. I campi lunghi si allargano solo se serve.
    Esempi:
Cliente
Destinazione
Indirizzo
Note

9. Un campo lungo con testo corto non deve occupare spazio inutile.

10. Se il campo non entra nello spazio residuo:
    va a capo.

11. Se nemmeno su riga nuova basta:
    aumenta lo span fino al massimo disponibile.

12. I campi multilinea possono aumentare altezza se necessario.

13. I campi multilinea, se restano stretti, vanno preferibilmente a capo.

14. I pulsanti restano sulla stessa riga finché ci stanno.

16. Se i pulsanti non ci stanno:
    vanno a capo in modo ordinato.

17. Label compatte:
    circa 12px.

18. Valori leggibili:
    circa 14px.

19. Altezza minima celle uniforme:
    circa 42px.

20. Celle statiche possono avere sfondo grigio molto chiaro.

21. Input editabili con sfondo bianco.

22. Spazi tra celle ridotti:
    circa 4px.

23. Ricalcolo automatico layout:
- caricamento pagina
    - resize finestra
        - apertura collapse
            - aggiornamenti ajax

24. Deve funzionare sia in view che edit.

25. Regola principale finale:

Usare il minimo spazio necessario, evitando righe brutte, spezzate o disallineate.
    
La parte Javascript della gestione è nel file smart-form.js
    **/
/* =========================================================
   SMART FORM - VERSIONE CORRETTA
   Mantiene la tua struttura ma corregge i punti critici:
   - sf-wrap realmente espandibile in verticale
   - niente height rigidi sui campi normali
   - overflow corretto
   - label/content allineati
========================================================= */

.smart-form {
    --smart-gap: 4px;
    --smart-border: #d8dde3;
    --smart-bg: #f8f9fa;
    --smart-bg-input: #ffffff;
    --smart-text: #24384a;
    --smart-value-text: #1d2c3a;
    --smart-content-offset-y: 0px;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--smart-gap);
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
}

    /* =========================================================
   CELLA BASE
========================================================= */

    .smart-form > .sf-item {
        grid-column: span 1;
        min-width: 0;
        max-width: 100%;
        min-height: 42px;
        height: auto;
        padding: 4px 8px;
        border: 1px solid var(--smart-border);
        border-radius: 4px;
        background: var(--smart-bg);
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        overflow: hidden;
        box-sizing: border-box;
    }

        /* =========================================================
   SPAN
========================================================= */

        .smart-form > .sf-item[data-span="1"] {
            grid-column: span 1;
        }

        .smart-form > .sf-item[data-span="2"] {
            grid-column: span 2;
        }

        .smart-form > .sf-item[data-span="3"] {
            grid-column: span 3;
        }

        .smart-form > .sf-item[data-span="4"] {
            grid-column: span 4;
        }

        .smart-form > .sf-item[data-span="5"] {
            grid-column: span 5;
        }

        .smart-form > .sf-item[data-span="6"] {
            grid-column: span 6;
        }

        .smart-form > .sf-item[data-span="7"] {
            grid-column: span 7;
        }

        .smart-form > .sf-item[data-span="8"] {
            grid-column: span 8;
        }

        .smart-form > .sf-item[data-span="9"] {
            grid-column: span 9;
        }

        .smart-form > .sf-item[data-span="10"] {
            grid-column: span 10;
        }

        .smart-form > .sf-item[data-span="11"] {
            grid-column: span 11;
        }

        .smart-form > .sf-item[data-span="12"] {
            grid-column: span 12;
        }

        /* =========================================================
   LABEL
========================================================= */

        .smart-form > .sf-item::before {
            content: attr(data-label);
            display: block;
            font-size: 12px;
            line-height: 12px;
            color: var(--smart-text);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            flex: 0 0 auto;
            margin: 0;
            padding: 0;
        }

        .smart-form > .sf-item:not([data-label])::before,
        .smart-form > .sf-item[data-label=""]::before {
            display: none;
        }

        /* =========================================================
   CONTENUTO STANDARD
========================================================= */

        .smart-form > .sf-item > :not(.sf-group),
        .smart-form > .sf-item > .smart_value {
            margin: 1px 0 0 0;
            min-width: 0;
            max-width: 100%;
            font-size: 14px;
            line-height: 15px;
            min-height: 15px;
            color: var(--smart-value-text);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            box-sizing: border-box;
        }

        /* =========================================================
   INPUT
========================================================= */

        .smart-form > .sf-item > .form-control,
        .smart-form > .sf-item > input:not([type=checkbox]):not([type=radio]),
        .smart-form > .sf-item > select,
        .smart-form > .sf-item > textarea,
        .smart-form > .sf-item > .smart_input:not(input[type=checkbox]):not(input[type=radio]) {
            width: 100%;
            min-width: 0;
            max-width: 100%;
            height: 15px !important;
            min-height: 15px !important;
            line-height: 15px !important;
            margin: 1px 0 0 0 !important;
            padding: 0 !important;
            border: 0 !important;
            outline: 0 !important;
            box-shadow: none !important;
            background: transparent !important;
            border-radius: 0 !important;
            font-size: 14px !important;
            color: var(--smart-value-text);
            box-sizing: border-box;
        }

        .smart-form > .sf-item.sf-has-input {
            background: var(--smart-bg-input);
        }

        /* =========================================================
   MULTILINE
========================================================= */

        .smart-form > .sf-item.sf-multiline {
            min-height: 64px;
        }

            .smart-form > .sf-item.sf-multiline > :not(.sf-group),
            .smart-form > .sf-item.sf-multiline > .smart_value,
            .smart-form > .sf-item.sf-multiline > textarea {
                white-space: normal;
                overflow: visible;
                text-overflow: clip;
                height: auto !important;
                min-height: 32px !important;
                line-height: 1.2 !important;
            }

        /* =========================================================
   WRAP (DESTINAZIONE / NOTE)
========================================================= */

        .smart-form > .sf-item.sf-wrap {
            overflow: visible;
        }

            .smart-form > .sf-item.sf-wrap > :not(.sf-group),
            .smart-form > .sf-item.sf-wrap > .smart_value,
            .smart-form > .sf-item.sf-wrap > span,
            .smart-form > .sf-item.sf-wrap > label,
            .smart-form > .sf-item.sf-wrap > a {
                white-space: normal;
                overflow: visible;
                text-overflow: clip;
                overflow-wrap: anywhere;
                word-break: break-word;
                line-height: 1.2;
            }

    /* =========================================================
   GROUP
========================================================= */

    .smart-form .sf-group {
        display: flex;
        flex-wrap: nowrap;
        gap: 4px;
        align-items: center;
        width: 100%;
        min-width: 0;
    }

        .smart-form .sf-group > .form-control,
        .smart-form .sf-group > input:not([type=button]):not([type=submit]):not([type=checkbox]):not([type=radio]),
        .smart-form .sf-group > select,
        .smart-form .sf-group > textarea,
        .smart-form .sf-group > .smart_input:not(input[type=checkbox]):not(input[type=radio]) {
            flex: 1 1 auto;
            min-width: 0;
            height: 15px !important;
            line-height: 15px !important;
            padding: 0 !important;
            border: 0 !important;
            background: transparent !important;
        }

        .smart-form .sf-group > .sf-addon {
            flex: 0 0 auto;
            font-size: 14px;
            line-height: 15px;
            white-space: nowrap;
        }

    /* =========================================================
   BUTTON ROW
========================================================= */

    .smart-form .sf-item.sf-item-buttons {
        grid-column: span 2;
        border: 0 !important;
        background: transparent !important;
        padding: 0 !important;
        min-height: auto !important;
    }

    .smart-form .sf-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        align-items: center;
    }

    /* =========================================================
   CHECKBOX
========================================================= */

    .smart-form .sf-item.sf-checkbox {
        background: var(--smart-bg-input);
    }

        .smart-form .sf-item.sf-checkbox input[type="checkbox"] {
            width: 14px !important;
            height: 14px !important;
            transform: scale(1.1);
        }

/* =========================================================
   RESPONSIVE
========================================================= */

/* LG */
@media (max-width:1199.98px) {
    .smart-form {
        grid-template-columns: repeat(8, minmax(0,1fr));
    }
}

/* MD */
@media (max-width:991.98px) {
    .smart-form {
        grid-template-columns: repeat(6, minmax(0,1fr));
    }

        .smart-form > .sf-item {
            min-height: 38px;
            padding: 4px 6px;
        }
}

/* SM */
@media (max-width:767.98px) {
    .smart-form {
        grid-template-columns: repeat(4, minmax(0,1fr));
    }

        .smart-form > .sf-item {
            min-height: 36px;
            padding: 4px 5px;
        }
}

/* XSM */
@media (max-width:575.98px) {
    .smart-form {
        --smart-gap: 2px;
        grid-template-columns: repeat(3, minmax(0,1fr));
    }

        .smart-form > .sf-item {
            min-height: 34px;
            padding: 3px 4px;
        }

            .smart-form > .sf-item::before {
                font-size: 10px;
                line-height: 10px;
            }

            .smart-form > .sf-item > :not(.sf-group),
            .smart-form > .sf-item > .smart_value {
                font-size: 12px;
                line-height: 13px;
            }
}