/*
 * Public forms ("Chiedi di entrare", "Segnala una sosta") and their confirmation pages.
 * Only on the pages that use them (frontend\assets\ModuloAsset). DESIGN.md, "Moduli".
 *
 * - Fields: white, 2px pine frame, same 48px height for inputs, selects and dates. Hover and focus
 *   are petrol (--petrolio): frame + 3px ring. Black only for errors (a state), never as decoration.
 * - Order inside a field: label (with the "facoltativo" mark), hint, error, control. Hint and error
 *   sit above the control: on the phone the keyboard hides what is below.
 * - Groups open on the "D" line, like every h2 of the site.
 * - "Cosa succede dopo": a stretch of pine road with the step numbers painted on the asphalt,
 *   beside the form from 64em, under it on the phone. The one bold element of these pages.
 */

/* ------------------------------------------------------------- page frame */

.modulo-pagina {
    --campo-bordo: var(--strada);
    --campo-attivo: var(--petrolio);
}

/* Focus on these pages is petrol, like every hover and touch (owner's rule). */
.modulo-pagina :focus-visible {
    outline-color: var(--campo-attivo);
}

.modulo-pagina .pagina-intestazione__sotto {
    max-width: 38rem;
}

.modulo {
    max-width: 40rem;
}

/* ------------------------------------------------------------------ groups */

.modulo fieldset {
    min-width: 0;
    margin: 0 0 var(--s6);
    padding: 0;
    border: 0;
}

/* A floated legend loses the browser's special rendering (the inset and the gap in the frame):
   it then lines up with the labels and can carry the D line like an h2. */
.modulo legend {
    position: relative;
    float: left;
    width: 100%;
    margin: 0 0 var(--s4);
    padding: calc(var(--linea-h) + var(--s3)) 0 0;
    font: var(--t-sezione);
}

.modulo legend + * {
    clear: both;
}

.modulo legend::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: calc(var(--linea-onda-l) - 16px);
    height: var(--linea-h);
    background:
        var(--linea-monti) no-repeat 0 0 / var(--linea-monti-l) var(--linea-h),
        linear-gradient(var(--strada), var(--strada)) no-repeat calc(var(--linea-monti-l) - 2px) 9px / calc(100% - var(--linea-monti-l) + 2px) 6px;
}

.modulo legend::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: var(--linea-onda-l);
    height: var(--linea-h);
    background: var(--linea-onda) no-repeat 0 0 / 100% 100%;
}

/* A sentence that belongs to the whole group ("Basta una delle due cose"). */
.modulo__nota {
    max-width: 38rem;
    margin: 0 0 var(--s4);
}

/* ------------------------------------------------------------------ fields */

.campo,
.campo-gruppo {
    margin-bottom: var(--s5);
}

.campo label,
.campo__etichetta {
    display: block;
    margin-bottom: var(--s1);
    font-weight: 700;
}

/* "facoltativo" beside the label, not a line of help under the field. */
.campo__facoltativo {
    color: var(--tratteggio);
    font-weight: 400;
}

.campo__aiuto {
    display: block;
    max-width: 38rem;
    margin: 0 0 var(--s2);
    font: var(--t-meta);
}

.campo__errore {
    display: block;
    margin: 0 0 var(--s2);
    font-weight: 700;
}

.campo input:not([type="checkbox"]):not([type="radio"]),
.campo select,
.campo textarea {
    display: block;
    width: 100%;
    height: var(--tocco);
    margin: 0;
    padding: 0 var(--s3);
    border: 2px solid var(--campo-bordo);
    border-radius: var(--raggio);
    background-color: var(--fondo);
    color: var(--testo);
    font: inherit;
    line-height: 1.5rem;
    -webkit-appearance: none;
    appearance: none;
}

.campo textarea {
    height: auto;
    min-height: 8rem;
    padding: var(--s2) var(--s3);
    resize: vertical;
}

/* The select draws its own chevron (deep petrol, written in the data URI: #1D4A53 = --strada),
   so it is exactly as tall as the inputs on every browser. */
.campo select {
    padding-right: 2.75rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 10'%3E%3Cpath d='M2 2l6 6 6-6' fill='none' stroke='%231D4A53' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--s3) center;
    background-size: 1rem .625rem;
    text-overflow: ellipsis;
    cursor: pointer;
}

/* Native date picker icon: keep it, keep the height. */
.campo input[type="date"] {
    min-width: 0;
}

.campo input:not([type="checkbox"]):not([type="radio"]):hover,
.campo select:hover,
.campo textarea:hover {
    border-color: var(--campo-attivo);
}

.campo input:not([type="checkbox"]):not([type="radio"]):focus,
.campo select:focus,
.campo textarea:focus {
    border-color: var(--campo-attivo);
    outline: 3px solid var(--campo-attivo);
    outline-offset: 2px;
}

/* Error: a state, so black. Left bar + thicker frame + bold message, never red. */
.campo--errore {
    padding-left: var(--s3);
    border-left: 6px solid var(--testo);
}

.campo--errore input:not([type="checkbox"]):not([type="radio"]),
.campo--errore select,
.campo--errore textarea {
    border: 3px solid var(--testo);
}

.modulo__coppia {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--s3);
}

/* Labels of different length (or an error on one side) still put both fields on the same line. */
.modulo__coppia > .campo {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.campo-gruppo .modulo__coppia > .campo {
    margin-bottom: 0;
}

.modulo__posizione[hidden] {
    display: none;
}

.modulo__posizione {
    margin: 0 0 var(--s3);
}

/* ----------------------------------------------------------------- choices */

/* Thin pine frame; ticked: thicker frame (inset, nothing moves) and bold. */
.scelte-pubbliche {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 10rem), 1fr));
    gap: var(--s2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.scelta {
    display: flex;
    align-items: center;
    gap: var(--s2);
    height: 100%;
    min-height: var(--tocco);
    padding: var(--s1) var(--s3);
    border: 2px solid var(--campo-bordo);
    border-radius: var(--raggio);
    background: var(--fondo);
    line-height: 1.25rem;
    cursor: pointer;
    -webkit-hyphens: auto;
    hyphens: auto;
}

.campo .scelta {
    display: flex;
    margin: 0;
    font-weight: 400;
}

.scelta input {
    flex: none;
    width: 1.375rem;
    height: 1.375rem;
    margin: 0;
    accent-color: var(--strada);
    cursor: pointer;
}

.scelta:hover {
    border-color: var(--campo-attivo);
    color: var(--campo-attivo);
}

.scelta:has(input:checked) {
    box-shadow: inset 0 0 0 1px var(--campo-bordo);
    font-weight: 700;
}

.scelta:has(input:checked):hover {
    box-shadow: inset 0 0 0 1px var(--campo-attivo);
}

.scelta:has(input:focus-visible) {
    outline: 3px solid var(--campo-attivo);
    outline-offset: 2px;
}

.scelta input:focus-visible {
    outline: none;
}

/* Consent: a long sentence, so ticked stays regular weight; the link inside keeps its colour. */
.scelta--consenso {
    align-items: flex-start;
    gap: var(--s3);
    padding-top: var(--s3);
    padding-bottom: var(--s3);
    line-height: 1.5rem;
    -webkit-hyphens: manual;
    hyphens: manual;
}

.campo .scelta--consenso,
.scelta--consenso:has(input:checked) {
    font-weight: 400;
}

.scelta--consenso input {
    margin-top: .0625rem;
}

.campo--errore .scelta {
    border-color: var(--testo);
}

/* Honeypot: off screen for people, still in the DOM for bots. */
.trappola {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Summary of errors at the top: black, it is a state. */
.avviso-modulo {
    max-width: 40rem;
    margin: 0 0 var(--s5);
    padding: var(--s3) var(--s4);
    border: 3px solid var(--testo);
    border-left-width: 8px;
    border-radius: var(--raggio);
    font-weight: 700;
}

.avviso-modulo > p {
    margin: 0;
}

/* Elenco dei campi da sistemare: ogni voce porta al campo. */
.avviso-modulo__elenco {
    margin: var(--s2) 0 0;
    padding-left: 1.25rem;
    font-weight: 400;
}

/* ------------------------------------------------------------------ buttons */

.modulo__invio {
    margin-top: var(--s5);
}

.modulo__invio .bottone {
    width: 100%;
}

/* The second button is outlined in deep petrol, not black: black is for states and prohibitions. */
.modulo-pagina .bottone--secondario {
    border-color: var(--strada);
    color: var(--strada);
}

.modulo-pagina .bottone--secondario:hover {
    border-color: var(--petrolio);
    background: var(--petrolio);
    color: var(--fondo);
}

.modulo-pagina .bottone:active {
    border-color: var(--strada);
    background: var(--strada);
    color: var(--fondo);
}

.modulo-pagina .bottone--secondario:active {
    border-color: var(--petrolio);
    background: var(--petrolio);
    color: var(--fondo);
}

.modulo-pagina__azioni {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--s2) var(--s5);
    margin-top: var(--s5);
}

.modulo-pagina__account {
    max-width: 38rem;
}

@media (min-width: 36em) {
    .modulo__invio .bottone {
        width: auto;
        min-width: 16rem;
    }
}

/* --------------------------------------------------- "cosa succede dopo" */

/*
 * A stretch of pine road down the left with the step numbers painted on it in white, stretched
 * upwards like the words painted on asphalt; the white centre line runs between them.
 * Pine and white only: this road is not a state (no solid/dashed/zebra joins).
 */
.percorso {
    --carreggiata: 2.5rem;
    --stacco-testo: var(--s4);
    position: relative;
    margin: 0 0 var(--s5);
    padding: 0 0 0 calc(var(--carreggiata) + var(--stacco-testo));
    list-style: none;
    counter-reset: tappa;
}

.percorso::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--carreggiata);
    border-radius: var(--raggio);
    background: var(--strada);
}

.percorso__tappa {
    position: relative;
    min-height: 4.5rem;
    padding: var(--s2) 0 var(--s5);
    counter-increment: tappa;
}

.percorso__tappa:last-child {
    min-height: 0;
    padding-bottom: var(--s3);
}

/* The painted number. */
.percorso__tappa::before {
    content: counter(tappa);
    content: counter(tappa) / "";
    position: absolute;
    top: var(--s2);
    left: calc(-1 * (var(--carreggiata) + var(--stacco-testo)));
    width: var(--carreggiata);
    color: var(--fondo);
    font: 800 1.25rem/1.625rem var(--famiglia);
    font-variant-numeric: tabular-nums;
    text-align: center;
    transform: scaleY(1.45);
    transform-origin: 50% 0;
}

/* The centre line from under the number to the next one. */
.percorso__tappa:not(:last-child)::after {
    content: "";
    position: absolute;
    top: 3.25rem;
    bottom: var(--s1);
    left: calc(-1 * (var(--carreggiata) + var(--stacco-testo)) + var(--carreggiata) / 2 - 1px);
    width: 2px;
    background: var(--mezzeria);
}

/* Il passo che tocca adesso: in grassetto, con la parola "Adesso" sopra (la forma e il testo, mai solo il colore). */
.percorso__tappa--adesso {
    font-weight: 700;
}

.percorso__adesso {
    display: block;
    font: var(--t-meta);
    font-weight: 700;
}

/* --------------------------------------------- side column from 64em */

@media (min-width: 64em) {
    /* Wider column only for the two forms: form on the left, "what happens next" on the right. */
    body:has(.modulo-pagina--doppia) {
        --colonna: 68rem;
    }

    .modulo-pagina--doppia {
        display: grid;
        grid-template-columns: minmax(0, 40rem) minmax(16rem, 1fr);
        column-gap: calc(2 * var(--s6));
        align-items: start;
    }

    .modulo-pagina--doppia > * {
        grid-column: 1;
    }

    .modulo-pagina--doppia > .modulo-pagina__lato {
        position: sticky;
        top: var(--s5);
        grid-column: 2;
        grid-row: 2 / span 2;
    }

    /* Its D line sits on the same level as the one of the first group. */
    .modulo-pagina__lato h2 {
        margin-top: 0;
    }

    .modulo-pagina--doppia:has(> .avviso-modulo) > .modulo-pagina__lato {
        grid-row: 3 / span 2;
    }
}

/* ------------------------------------------------- tipo di camper (Registrati) */

/*
 * Sei riquadri con la sagoma sopra il nome (DESIGN.md, "Tipologie di camper"), stesso linguaggio
 * delle .scelta. Tre per riga sempre: il modulo resta largo 40 rem e a sei "Semintegrale" non ci sta.
 * La radio sta nell'angolo in alto a sinistra, la sagoma e il nome centrati sotto.
 */
.scelte-pubbliche.scelte--camper {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.campo .scelta--camper {
    position: relative;
    flex-direction: column;
    justify-content: flex-end;
    gap: var(--s1);
    padding: 2.25rem var(--s1) var(--s2);
    font: var(--t-meta);
    text-align: center;
}

.scelta--camper input {
    position: absolute;
    top: var(--s2);
    left: var(--s2);
}

.scelta--camper .camper {
    width: 4rem;
}
