/**
 * CustomForm - Frontend styles
 * File: assets/css/customform.css
 *
 * Stili dei moduli renderizzati con [customform id="X"].
 * Ereditano il font del tema; i colori usano variabili modificabili.
 *
 * @package CustomForm
 */

/* -------------------------------------------------------------------------
 * 1. Variabili (sovrascrivibili dal tema con .customform { --cf-... })
 * ---------------------------------------------------------------------- */

.customform {
    --cf-primary:        #2271b1;
    --cf-primary-hover:  #135e96;
    --cf-primary-light:  #f0f6fc;
    --cf-success:        #00a32a;
    --cf-success-bg:     #edfaef;
    --cf-error:          #d63638;
    --cf-error-bg:       #fcf0f1;
    --cf-text:           #1d2327;
    --cf-text-muted:     #50575e;
    --cf-border:         #c3c4c7;
    --cf-border-focus:   #2271b1;
    --cf-bg:             #ffffff;
    --cf-bg-subtle:      #f6f7f7;
    --cf-radius:         4px;
    --cf-radius-lg:      8px;
    --cf-gap:            18px;
    --cf-gap-sm:         8px;
    --cf-font-size:      15px;
    --cf-line-height:    1.5;
    --cf-transition:     0.15s ease-in-out;
}

/* -------------------------------------------------------------------------
 * 2. Contenitore del modulo
 * ---------------------------------------------------------------------- */

.customform {
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    margin: 0 0 24px;
    padding: 0;
    font-size: var(--cf-font-size);
    line-height: var(--cf-line-height);
    color: var(--cf-text);
    font-family: inherit;
}

.customform *,
.customform *::before,
.customform *::after {
    box-sizing: border-box;
}

/* Se il modulo è dentro una card (opzionale: .customform--card) */
.customform--card {
    padding: 28px;
    background: var(--cf-bg);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius-lg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

/* -------------------------------------------------------------------------
 * 3. Gruppo campo (label + input + help)
 * ---------------------------------------------------------------------- */

.cf-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--cf-gap);
}

.cf-field:last-of-type {
    margin-bottom: 0;
}

.cf-field > label,
.cf-field__label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    font-size: 0.95em;
    color: var(--cf-text);
    cursor: pointer;
}

.cf-field__required {
    color: var(--cf-error);
    font-weight: 700;
    margin-left: 2px;
}

.cf-field__help {
    font-size: 0.85em;
    color: var(--cf-text-muted);
    margin: 0;
}

/* -------------------------------------------------------------------------
 * 4. Input, textarea, select
 * ---------------------------------------------------------------------- */

.customform input[type="text"],
.customform input[type="email"],
.customform input[type="tel"],
.customform input[type="url"],
.customform input[type="number"],
.customform input[type="date"],
.customform input[type="password"],
.customform input[type="search"],
.customform textarea,
.customform select {
    display: block;
    width: 100%;
    padding: 10px 12px;
    font-family: inherit;
    font-size: 1em;
    line-height: 1.4;
    color: var(--cf-text);
    background: var(--cf-bg);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
    transition: border-color var(--cf-transition), box-shadow var(--cf-transition);
    -webkit-appearance: none;
    appearance: none;
}

.customform textarea {
    min-height: 120px;
    resize: vertical;
}

.customform select {
    /* Freccia custom (evita quella di sistema) */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2350575e%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
    padding-right: 34px;
}

.customform input:hover:not(:disabled):not(:focus),
.customform textarea:hover:not(:disabled):not(:focus),
.customform select:hover:not(:disabled):not(:focus) {
    border-color: #8c8f94;
}

.customform input:focus,
.customform textarea:focus,
.customform select:focus {
    outline: none;
    border-color: var(--cf-border-focus);
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
}

.customform input:disabled,
.customform textarea:disabled,
.customform select:disabled {
    background: var(--cf-bg-subtle);
    color: var(--cf-text-muted);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Placeholder */
.customform input::placeholder,
.customform textarea::placeholder {
    color: #8c8f94;
    opacity: 1;
}

/* Input file */
.customform input[type="file"] {
    width: 100%;
    padding: 8px;
    font-size: 0.9em;
    background: var(--cf-bg-subtle);
    border: 1px dashed var(--cf-border);
    border-radius: var(--cf-radius);
    cursor: pointer;
}

.customform input[type="file"]:hover {
    border-color: var(--cf-primary);
    background: var(--cf-primary-light);
}

.customform input[type="file"]::file-selector-button {
    padding: 6px 12px;
    margin-right: 10px;
    background: var(--cf-primary);
    color: #fff;
    border: none;
    border-radius: var(--cf-radius);
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--cf-transition);
}

.customform input[type="file"]::file-selector-button:hover {
    background: var(--cf-primary-hover);
}

/* -------------------------------------------------------------------------
 * 5. Radio e checkbox
 * ---------------------------------------------------------------------- */

.cf-field--radio .cf-field__options,
.cf-field--checkbox .cf-field__options {
    display: flex;
    flex-direction: column;
    gap: var(--cf-gap-sm);
    margin-top: 4px;
}

.cf-option {
    display: inline-flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    background: var(--cf-bg);
    border: 1px solid var(--cf-border);
    border-radius: var(--cf-radius);
    cursor: pointer;
    font-size: 1em;
    line-height: 1.4;
    transition: all var(--cf-transition);
    user-select: none;
}

.cf-option:hover {
    border-color: var(--cf-primary);
    background: var(--cf-primary-light);
}

.cf-option input[type="radio"],
.cf-option input[type="checkbox"] {
    position: relative;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin: 2px 0 0;
    cursor: pointer;
    accent-color: var(--cf-primary);
}

.cf-option:has(input:checked) {
    border-color: var(--cf-primary);
    background: var(--cf-primary-light);
    color: var(--cf-primary-hover);
    font-weight: 500;
}

.cf-option:has(input:focus-visible) {
    outline: 2px solid var(--cf-primary);
    outline-offset: 2px;
}

/* Fallback per browser senza :has() */
@supports not selector(:has(*)) {
    .cf-option input:checked + span {
        font-weight: 600;
        color: var(--cf-primary-hover);
    }
}

/* Checkbox singolo (accetto termini, ecc.) */
.cf-field--checkbox-single {
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
}

.cf-field--checkbox-single input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    accent-color: var(--cf-primary);
    flex-shrink: 0;
}

/* -------------------------------------------------------------------------
 * 6. Stato errore del campo
 * ---------------------------------------------------------------------- */

.cf-field.has-error input,
.cf-field.has-error textarea,
.cf-field.has-error select {
    border-color: var(--cf-error);
    background: #fff;
}

.cf-field.has-error input:focus,
.cf-field.has-error textarea:focus,
.cf-field.has-error select:focus {
    box-shadow: 0 0 0 2px rgba(214, 54, 56, 0.15);
}

.cf-field__error {
    font-size: 0.85em;
    color: var(--cf-error);
    margin: 2px 0 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cf-field__error::before {
    content: "⚠";
    font-size: 1em;
}

/* -------------------------------------------------------------------------
 * 7. Honeypot (campo anti-bot nascosto) + timing check
 * ---------------------------------------------------------------------- */

.cf-honeypot,
.cf-timing-check {
    position: absolute !important;
    left: -9999px !important;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

/* -------------------------------------------------------------------------
 * 8. Pulsante di submit
 * ---------------------------------------------------------------------- */

.cf-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    margin-top: var(--cf-gap);
    font-family: inherit;
    font-size: 1em;
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: var(--cf-primary);
    border: none;
    border-radius: var(--cf-radius);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--cf-transition), transform var(--cf-transition);
    -webkit-appearance: none;
    appearance: none;
}

.cf-submit:hover:not(:disabled) {
    background: var(--cf-primary-hover);
}

.cf-submit:active:not(:disabled) {
    transform: translateY(1px);
}

.cf-submit:focus-visible {
    outline: 2px solid var(--cf-primary);
    outline-offset: 2px;
}

.cf-submit:disabled,
.cf-submit[aria-busy="true"] {
    opacity: 0.65;
    cursor: not-allowed;
}

/* Spinner dentro il pulsante durante l'invio */
.cf-submit[aria-busy="true"]::before {
    content: "";
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cf-spin 0.7s linear infinite;
}

@keyframes cf-spin {
    to { transform: rotate(360deg); }
}

/* Pulsante a larghezza piena (opzionale) */
.cf-submit--full {
    width: 100%;
}

/* -------------------------------------------------------------------------
 * 9. Messaggi (successo / errore globali)
 * ---------------------------------------------------------------------- */

.cf-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    margin: 0 0 var(--cf-gap);
    font-size: 0.95em;
    line-height: 1.5;
    border-radius: var(--cf-radius);
    border-left: 4px solid var(--cf-primary);
    background: var(--cf-primary-light);
    color: var(--cf-text);
}

.cf-message--success {
    border-left-color: var(--cf-success);
    background: var(--cf-success-bg);
    color: #007017;
}

.cf-message--error {
    border-left-color: var(--cf-error);
    background: var(--cf-error-bg);
    color: #a02226;
}

.cf-message__icon {
    flex-shrink: 0;
    font-size: 1.1em;
    line-height: 1.4;
}

.cf-message__text {
    flex: 1;
}

.cf-message p:last-child {
    margin-bottom: 0;
}

/* Se il modulo è nascosto dopo l'invio */
.customform.is-submitted {
    display: none;
}

/* -------------------------------------------------------------------------
 * 10. Anti-spam: reCAPTCHA badge
 * ---------------------------------------------------------------------- */

.cf-recaptcha-notice {
    font-size: 0.75em;
    color: var(--cf-text-muted);
    margin-top: 12px;
    line-height: 1.4;
}

.cf-recaptcha-notice a {
    color: var(--cf-primary);
    text-decoration: underline;
}

/* -------------------------------------------------------------------------
 * 11. Utility
 * ---------------------------------------------------------------------- */

.customform .cf-hidden {
    display: none !important;
}

.customform .cf-visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* -------------------------------------------------------------------------
 * 12. Responsive
 * ---------------------------------------------------------------------- */

@media (max-width: 600px) {
    .customform {
        --cf-font-size: 16px; /* evita zoom automatico su iOS */
    }

    .cf-submit {
        width: 100%;
        padding: 14px 20px;
    }

    .customform--card {
        padding: 20px;
    }
}

/* -------------------------------------------------------------------------
 * 13. Tema scuro automatico (prefers-color-scheme)
 * ---------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
    /* Attivalo solo se il tuo sito supporta il dark mode.
       Di default è commentato per non interferire col tema. */

    /*
    .customform {
        --cf-text:        #e0e0e0;
        --cf-text-muted:  #a0a0a0;
        --cf-border:      #4a4a4a;
        --cf-bg:          #1e1e1e;
        --cf-bg-subtle:   #2a2a2a;
        --cf-primary-light: #1a3a5c;
    }
    */
}

/* -------------------------------------------------------------------------
 * 14. Stampa
 * ---------------------------------------------------------------------- */

@media print {
    .customform {
        max-width: 100%;
    }

    .cf-submit {
        display: none;
    }

    .cf-field input,
    .cf-field textarea,
    .cf-field select {
        border: 1px solid #000;
        background: transparent;
    }
}