/* ===================================
   AREA RISERVATA v1.5 - REFINED DESIGN
   Design pulito e professionale con modifiche richieste
   =================================== */

/* ===================================
   DESIGN SYSTEM FOUNDATION
   =================================== */

:root {
    /* Primary Palette */
    --sage-green: #28b061;
    --sage-dark: #1d8557;
    --sage-light: #a7f3d0;
    --sage-pale: #ecfdf5;

    /* Accent Gold */
    --gold: #ebd35b;
    --gold-dark: #d4a920;
    --gold-light: #fef3c7;

    /* Neutrals */
    --slate-900: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --slate-600: #475569;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-300: #cbd5e1;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --slate-50: #f8fafc;

    /* Semantic Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 16px 32px rgba(0, 0, 0, 0.12);
    --shadow-2xl: 0 24px 48px rgba(0, 0, 0, 0.14);

    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-8: 3rem;
    --space-10: 4rem;

    /* Border Radius */
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.5rem;
    --radius-full: 9999px;

    /* Timing */
    --ease-in-out-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out-back: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-spring: cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ===================================
   FORM CONTAINER
   =================================== */

.scheda-catalogo-form {
    max-width: 980px;
    margin: var(--space-10) auto;
    padding: 0;
    font-family: 'Karla', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===================================
   HERO SECTION - SENZA FONDINO, SU UNA RIGA
   =================================== */

.form-intro {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    background: transparent;
    padding: 0 0 var(--space-6) 0;
    margin-bottom: var(--space-4);
    border: none;
    border-left: none;
}

.form-intro strong {
    font-size: 1.125rem;
    color: var(--slate-700);
    font-weight: 700;
    font-family: 'Karla', sans-serif;
}

/* CTA Button - SULLA STESSA RIGA */
.btn-regolamento {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--sage-green);
    color: white !important;
    text-decoration: none !important;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.8125rem;
    box-shadow: none;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.btn-regolamento::after {
    content: "→";
    margin-left: var(--space-1);
    transition: transform 0.3s ease;
}

.btn-regolamento:hover {
    background: var(--sage-dark);
    transform: none;
    text-decoration: none !important;
}

.btn-regolamento:hover::after {
    transform: translateX(4px);
}

/* ===================================
   FORM SHELL - SENZA BANDA NERA E SENZA FONDINO
   =================================== */

#form-iscrizione-pubblica,
#scheda-catalogo-form {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    border: none;
}

/* RIMOSSO: Title bar nera */
.form-title {
    display: none;
}

/* ===================================
   FORM SECTIONS - SENZA FONDINO BIANCO
   =================================== */

.form-section {
    padding: var(--space-8) var(--space-6);
    position: relative;
    /* RIMOSSO: background bianco */
}

/* Dividers sottili */
.form-section::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: var(--space-6);
    right: var(--space-6);
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--slate-200), transparent);
}

.form-section:last-of-type::after {
    display: none;
}

/* Service Section - Larga come le altre, senza lucchetto */
.form-section.recapiti-compilatore {
    background: linear-gradient(135deg, var(--gold-light) 0%, #fffef5 100%);
    border-left: 6px solid var(--gold);
    border-radius: 0;
    box-shadow: inset 0 2px 12px rgba(235, 211, 91, 0.08);
    margin-bottom: var(--space-6);
}

.form-section.recapiti-compilatore .section-title::before {
    background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dark) 100%);
    box-shadow: 0 0 0 3px var(--gold-light), var(--shadow-sm);
}

.form-section.recapiti-compilatore .section-title {
    color: var(--gold-dark);
}

/* ===================================
   SECTION HEADERS
   =================================== */

.section-title {
    font-family: 'Bricolage Grotesque', Georgia, serif;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--slate-900);
    margin: 0 0 var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    letter-spacing: -0.03em;
}

.section-title::before {
    content: "";
    width: 6px;
    height: 42px;
    background: linear-gradient(180deg, var(--sage-green) 0%, var(--sage-dark) 100%);
    border-radius: var(--radius-full);
    box-shadow: 0 0 0 3px var(--sage-pale), var(--shadow-sm);
    flex-shrink: 0;
}

.section-title small {
    font-size: 0.75rem;
    color: var(--slate-600);
    font-weight: 500;
    font-family: 'Karla', sans-serif;
    background: transparent;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    border: none;
    margin-left: auto;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: none;
}

/* ===================================
   FORM LAYOUT
   =================================== */

.form-row {
    display: flex;
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.form-row:last-child {
    margin-bottom: 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    position: relative;
}

.form-group.full-width {
    flex: 1 1 100%;
}

.form-group.half-width {
    flex: 1 1 calc(50% - var(--space-3));
}

.form-group.third-width {
    flex: 1 1 calc(33.333% - var(--space-4));
}

/* ===================================
   LABELS - CON ASTERISCO (SENZA PALLINO)
   =================================== */

.form-group label {
    display: block;
    margin-bottom: var(--space-2);
    color: var(--slate-800);
    font-weight: 700;
    font-size: 0.8125rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    position: relative;
    padding-left: var(--space-4);
}

.form-group label::before {
    content: "▸";
    position: absolute;
    left: 0;
    color: var(--sage-green);
    font-size: 0.875rem;
    font-weight: 900;
}

.form-group label small {
    display: block;
    margin-top: var(--space-1);
    font-weight: 400;
    color: var(--slate-600);
    font-size: 0.8125rem;
    text-transform: none;
    font-style: italic;
    letter-spacing: 0;
    padding-left: 0;
}

.form-group label small::before {
    content: none;
}

/* Required Indicator disabilitato (asterisco è scritto nei label HTML) */
.form-group label:has(+ input[required])::after,
.form-group label:has(+ textarea[required])::after,
.form-group label:has(+ select[required])::after {
    content: none;
}

/* ===================================
   INPUT FIELDS
   =================================== */

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="url"],
.form-group input[type="tel"],
.form-group input[type="file"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: var(--space-4) var(--space-5);
    border: 2px solid var(--slate-200);
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-family: 'Karla', sans-serif;
    color: var(--slate-900);
    background: white;
    transition: all 0.3s var(--ease-in-out-smooth);
    box-sizing: border-box;
    box-shadow: var(--shadow-xs);
    line-height: 1.5;
}

.form-group input:hover,
.form-group textarea:hover,
.form-group select:hover {
    border-color: var(--slate-300);
    box-shadow: var(--shadow-sm);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--sage-green);
    box-shadow: 0 0 0 4px var(--sage-pale), 0 8px 16px rgba(40, 176, 97, 0.12);
    background: linear-gradient(to bottom, white 0%, var(--sage-pale) 100%);
    transform: translateY(-2px);
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.75;
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%2328b061' d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-5) center;
    padding-right: var(--space-10);
}

.form-group select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%2328b061' d='M8 6L13 11H3z'/%3E%3C/svg%3E");
    /* Senza questo la freccetta viene ripetuta su tutta la larghezza del
       campo quando il select ha il focus: ridefinire background-image da
       sola non eredita il no-repeat della regola base. */
    background-repeat: no-repeat;
    background-position: right var(--space-5) center;
}

/* ===================================
   CHARACTER COUNTER - COME VERSIONE PRECEDENTE
   =================================== */

.has-counter {
    position: relative;
}

.char-counter {
    display: block;
    margin-top: 8px;
    font-size: 13px;
    color: var(--sage-green);
    font-weight: 600;
    text-align: right;
    transition: color 0.3s ease;
}

.char-counter .current {
    font-weight: 700;
    font-size: 14px;
}

.char-counter.warning {
    color: var(--warning);
}

.char-counter.danger {
    color: var(--error);
    font-weight: 700;
}

/* ===================================
   HELP TEXT
   =================================== */

.form-help {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding: var(--space-3) var(--space-4);
    font-size: 0.8125rem;
    color: var(--slate-600);
    line-height: 1.6;
    background: var(--slate-50);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--info);
}

.form-help::before {
    content: "ℹ";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--info);
    color: white;
    border-radius: 50%;
    font-size: 0.6875rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 2px;
}

/* ===================================
   DYNAMIC FIELDS - SOLO SEZIONE VERDE
   =================================== */

#altre-sedi-container,
#file-allegati-container {
    margin-bottom: var(--space-5);
}

/* NASCONDO I PLACEHOLDER INIZIALI */
.no-sedi,
.no-files {
    display: none;
}

.altra-sede-item,
.file-allegato-item {
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
    padding: var(--space-5);
    background: white;
    border: 2px solid var(--slate-200);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    position: relative;
    transition: all 0.4s var(--ease-in-out-smooth);
    box-shadow: var(--shadow-sm);
}

.altra-sede-item::before,
.file-allegato-item::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    background: linear-gradient(180deg, var(--sage-green) 0%, var(--sage-dark) 100%);
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    opacity: 0;
    transition: opacity 0.3s;
}

.altra-sede-item:hover,
.file-allegato-item:hover {
    border-color: var(--sage-green);
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px) translateX(4px);
}

.altra-sede-item:hover::before,
.file-allegato-item:hover::before {
    opacity: 1;
}

.altra-sede-item input,
.file-allegato-item input,
.file-allegato-item textarea {
    flex: 1;
    min-width: 0;
    margin-bottom: 0 !important;
}

.altra-sede-item input[style*="width: 80px"],
.altra-sede-item input[style*="width: 60px"] {
    flex: 0 0 auto;
}

.file-allegato-item {
    flex-wrap: wrap;
}

.file-allegato-item input[type="text"],
.file-allegato-item input[type="url"] {
    flex: 1 1 calc(50% - var(--space-2));
}

.file-allegato-item textarea {
    flex: 1 1 100%;
    min-height: 80px;
}

/* ===================================
   REMOVE BUTTONS - PIATTI
   =================================== */

.btn-remove-sede,
.btn-remove-file {
    background: var(--error);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    box-shadow: none;
}

.btn-remove-sede:hover,
.btn-remove-file:hover {
    background: #dc2626;
    transform: rotate(90deg) scale(1.1);
}

/* ===================================
   ADD BUTTONS - PIATTI
   =================================== */

.btn-add-sede,
.btn-add-file {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    background: white;
    color: var(--sage-green);
    border: 2px dashed var(--sage-green);
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Karla', sans-serif;
    box-shadow: none;
}

.btn-add-sede::before,
.btn-add-file::before {
    content: "+";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--sage-green);
    color: white;
    border-radius: 50%;
    font-size: 20px;
    font-weight: 700;
    transition: all 0.3s ease;
}

.btn-add-sede:hover,
.btn-add-file:hover {
    background: var(--sage-green);
    color: white;
    border-style: solid;
}

.btn-add-sede:hover::before,
.btn-add-file:hover::before {
    background: white;
    color: var(--sage-green);
    transform: rotate(90deg);
}

/* ===================================
   SOCIAL LINKS - ICONA + INPUT
   =================================== */

.social-links-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.social-link-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

/* Icona fuori dal rettangolo */
.social-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: var(--slate-100);
    border-radius: var(--radius-md);
    color: var(--sage-green);
    font-size: 1.125rem;
    transition: all 0.3s ease;
    border: 2px solid var(--slate-200);
}

/* Input visibile accanto all'icona */
.social-link-item input {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    border: 2px solid var(--slate-200);
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    font-family: 'Karla', sans-serif;
    color: var(--slate-900);
    background: white;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

.social-link-item input:hover {
    border-color: var(--slate-300);
}

.social-link-item input:focus {
    outline: none;
    border-color: var(--sage-green);
    box-shadow: 0 0 0 3px var(--sage-pale);
}

/* Quando l'input ha un valore, evidenzia l'icona */
.social-link-item:has(input:not([value=""])) .social-icon {
    background: var(--sage-green);
    color: white;
    border-color: var(--sage-green);
}

.social-link-item:hover .social-icon {
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(40, 176, 97, 0.2);
}

/* ===================================
   FORM ACTIONS
   =================================== */

.form-actions {
    padding: var(--space-4) var(--space-6);
    background: transparent;
    border-top: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-5);
}

.form-message {
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    font-weight: 600;
    text-align: center;
    display: none;
    width: 100%;
    max-width: 600px;
    box-shadow: var(--shadow-md);
}

.form-message.success {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    color: #065f46;
    border: 2px solid var(--success);
}

.form-message.success::before {
    content: "✓";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--success);
    color: white;
    border-radius: 50%;
    font-weight: 700;
}

.form-message.error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    color: #991b1b;
    border: 2px solid var(--error);
}

.form-message.error::before {
    content: "✕";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--error);
    color: white;
    border-radius: 50%;
    font-weight: 700;
}

/* ===================================
   SUBMIT BUTTON - COMPACT E PIATTO
   =================================== */

.btn-save {
    padding: var(--space-4) var(--space-8);
    max-width: 320px;
    background: var(--gold);
    color: var(--slate-900);
    border: none;
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 700;
    font-family: 'Karla', sans-serif;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: none;
    transition: all 0.3s ease;
    position: relative;
}

.btn-save::after {
    content: "→";
    margin-left: var(--space-2);
    transition: transform 0.3s ease;
    display: inline-block;
}

.btn-save:hover {
    background: var(--gold-dark);
}

.btn-save:hover::after {
    transform: translateX(6px);
}

.btn-save:active {
    opacity: 0.9;
}

.btn-save.loading {
    opacity: 0.8;
    cursor: wait;
    pointer-events: none;
}

.btn-save.loading::after {
    content: "";
    width: 16px;
    height: 16px;
    margin-left: var(--space-2);
    border: 2px solid var(--slate-900);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===================================
   ERROR MESSAGES
   =================================== */

.error-message {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding: var(--space-2) var(--space-3);
    color: var(--error);
    font-size: 0.8125rem;
    font-weight: 600;
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--error);
    box-shadow: var(--shadow-xs);
}

.error-message::before {
    content: "⚠";
    font-size: 1rem;
}

/* ===================================
   RESPONSIVE
   =================================== */

@media (max-width: 768px) {
    .scheda-catalogo-form {
        margin: var(--space-4) auto;
    }

    .form-intro {
        padding: var(--space-6) var(--space-4);
    }

    .form-section {
        padding: var(--space-6) var(--space-4);
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-group.half-width,
    .form-group.third-width {
        flex: 1 1 100%;
    }

    .altra-sede-item,
    .file-allegato-item {
        flex-direction: column;
    }

    .altra-sede-item input[style*="width: 80px"],
    .altra-sede-item input[style*="width: 60px"] {
        width: 100% !important;
    }

    .social-links-grid {
        grid-template-columns: 1fr;
    }

    .section-title {
        font-size: 1.5rem;
        flex-wrap: wrap;
    }

    .section-title small {
        width: 100%;
        margin-left: 0;
        margin-top: var(--space-2);
    }

    .btn-save {
        max-width: 100%;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .scheda-catalogo-form {
        border-radius: 0;
        margin: 0;
    }

    .form-intro {
        border-radius: 0;
    }

    #form-iscrizione-pubblica,
    #scheda-catalogo-form {
        border-radius: 0;
        box-shadow: none;
        border-left: none;
        border-right: none;
    }

    .form-section {
        padding: var(--space-5) var(--space-3);
    }
}

/* ===================================
   ACCESSIBILITY
   =================================== */

*:focus-visible {
    outline: 3px solid var(--sage-green);
    outline-offset: 4px;
    box-shadow: 0 0 0 6px var(--sage-pale);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: high) {
    .form-group input,
    .form-group textarea,
    .form-group select,
    .altra-sede-item,
    .file-allegato-item {
        border-width: 3px;
    }
}
