.ac-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height per mobile */
    display: none;
    z-index: 2147483647;
    backdrop-filter: blur(4px);
}

.ac-modal[aria-hidden="false"] {
    display: block;
    animation: ac-modal-fade-in 0.3s ease-out;
}

@keyframes ac-modal-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.ac-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .6);
    animation: ac-overlay-fade-in 0.3s ease-out;
}

@keyframes ac-overlay-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.ac-modal__dialog {
    position: relative;
    margin: 2rem auto;
    margin-top: max(2rem, 5vh);
    margin-bottom: max(2rem, 5vh);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3), 0 8px 30px rgba(0, 0, 0, .15);
    max-height: calc(100vh - 4rem);
    max-height: calc(100dvh - 4rem); /* Dynamic viewport per mobile */
    overflow: hidden;
    width: calc(100% - 40px);
    max-width: 800px;
    animation: ac-dialog-slide-in 0.3s ease-out;
    border: 1px solid rgba(255, 255, 255, .2);
}

@keyframes ac-dialog-slide-in {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.ac-modal__dialog-content {
    padding: 24px;
    overflow-y: auto;
    max-height: calc(100vh - 6rem);
    max-height: calc(100dvh - 6rem); /* Dynamic viewport per mobile */
}

.ac-modal__close {
    position: absolute;
    top: 16px;
    right: 16px;
    border: none;
    background: rgba(0, 0, 0, .05);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s ease;
    z-index: 10;
}

.ac-modal__close:hover {
    background: rgba(0, 0, 0, .1);
    color: #333;
    transform: scale(1.1);
}

.ac-modal__title {
    margin: 0 0 20px;
    font-size: 24px;
    font-weight: 700;
    color: #333;
    padding-right: 40px;
    border-bottom: 2px solid #f5c93f;
    padding-bottom: 12px;
}

.ac-modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.ac-modal-open body {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

html.ac-modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Form styling inside modal */
.ac-modal .gform_wrapper {
    max-width: none;
    margin: 0;
}

.ac-modal .gform_wrapper .gform_body {
    padding: 0;
}

.ac-modal .gform_wrapper .gform_fields {
    margin: 0;
    padding: 0;
}

.ac-modal .gform_wrapper .gfield {
    margin-bottom: 20px;
    padding: 0;
}

.ac-modal .gform_wrapper .gfield_label {
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.ac-modal .gform_wrapper input[type="text"],
.ac-modal .gform_wrapper input[type="email"],
.ac-modal .gform_wrapper input[type="tel"],
.ac-modal .gform_wrapper input[type="number"],
.ac-modal .gform_wrapper input[type="date"],
.ac-modal .gform_wrapper select,
.ac-modal .gform_wrapper textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: #fff !important;
    transition: border-color 0.2s ease;
}

/* Fix per autocomplete che aggiunge sfondi grigi */
.ac-modal .gform_wrapper input:-webkit-autofill,
.ac-modal .gform_wrapper input:-webkit-autofill:hover,
.ac-modal .gform_wrapper input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #fff inset !important;
    -webkit-text-fill-color: #333 !important;
    background: #fff !important;
}

.ac-modal .gform_wrapper input:focus,
.ac-modal .gform_wrapper select:focus,
.ac-modal .gform_wrapper textarea:focus {
    border-color: #f5c93f;
    outline: none;
    box-shadow: 0 0 0 3px rgba(245, 201, 63, 0.1);
}

.ac-modal .gform_wrapper .gform_footer {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.ac-modal .gform_wrapper .gform_footer input[type="submit"] {
    background: #f5c93f;
    border: 1px solid #f5c93f;
    color: #333;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ac-modal .gform_wrapper .gform_footer input[type="submit"]:hover {
    background: #f4c430;
    border-color: #f4c430;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(245, 201, 63, 0.3);
}

/* Triggers (backward compatible) */
button[data-modal-open],
a[data-modal-open],
[data-ac-modal-open] {
    cursor: pointer;
    color: #f5c93f;
    transition: all 0.2s ease;
}

button[data-modal-open]:hover,
a[data-modal-open]:hover,
[data-ac-modal-open]:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

/* Responsive improvements */
@media (max-width: 768px) {
    .ac-modal__dialog {
        margin: 1rem auto;
        margin-top: max(1rem, 2vh);
        margin-bottom: max(1rem, 2vh);
        width: calc(100% - 20px);
        max-height: calc(100vh - 2rem);
        max-height: calc(100dvh - 2rem); /* Dynamic viewport per mobile */
    }

    .ac-modal__dialog-content {
        padding: 16px;
        max-height: calc(100vh - 3rem);
        max-height: calc(100dvh - 3rem); /* Dynamic viewport per mobile */
    }

    .ac-modal__title {
        font-size: 20px;
        margin-bottom: 16px;
        padding-bottom: 8px;
    }

    .ac-modal__close {
        top: 12px;
        right: 12px;
        width: 28px;
        height: 28px;
        font-size: 18px;
    }
}

/* iOS specific fixes for body scroll lock */
@supports (-webkit-overflow-scrolling: touch) {
    .ac-modal-open {
        -webkit-overflow-scrolling: touch;
        touch-action: none;
    }

    .ac-modal-open body {
        -webkit-overflow-scrolling: touch;
        touch-action: none;
    }

    html.ac-modal-open {
        -webkit-overflow-scrolling: touch;
        touch-action: none;
    }

    .ac-modal__dialog-content {
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }
}

/* Extra safe mode per browser senza supporto dvh */
@supports not (height: 100dvh) {
    .ac-modal {
        height: 100vh;
        padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    }

    .ac-modal__dialog {
        max-height: calc(100vh - 4rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }

    .ac-modal__dialog-content {
        max-height: calc(100vh - 6rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }
}
