/* ==========================================================================
   Appointment request card (inc/appointment_form.php): fields, consultation type,
   errors and confirmation. Shared by appuntamento.php and primo-colloquio.php.
   Loaded after css/site.css; only tokens from site.css, classes prefixed .ap-.
   ========================================================================== */

/* Form card */
.ap-card {
    /* Field borders: 3:1 on --c-surface (non-text contrast AA), lighter than a full ink line. */
    --ap-border: color-mix(in srgb, var(--c-ink-soft) 72%, var(--c-surface));
    --ap-ring: 0 0 0 1px var(--c-teal), 0 0 0 5px color-mix(in srgb, var(--c-teal) 16%, transparent);

    padding: clamp(1.5rem, 0.9rem + 2.6vw, 3.25rem);
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.ap-card__head {
    margin-bottom: var(--space-6);
}

.ap-card__title {
    margin-bottom: var(--space-3);
    font-family: var(--font-serif);
    font-size: clamp(1.875rem, 1.45rem + 1.4vw, 2.625rem);
    font-weight: 500;
    line-height: 1.12;
    letter-spacing: -0.025em;
    text-wrap: balance;
}

.ap-card__title em {
    font-style: italic;
    font-weight: 400;
    color: var(--c-secondary-strong);
}

.ap-card__intro {
    max-width: 50ch;
    color: var(--c-ink-soft);
    text-wrap: pretty;
}

/* Server-side error, right above the fields */
.ap-alert {
    display: flex;
    gap: var(--space-4);
    align-items: flex-start;
    margin-bottom: var(--space-6);
    padding: var(--space-4) var(--space-5) var(--space-4) var(--space-4);
    background: var(--c-secondary-soft);
    border: 1px solid color-mix(in srgb, var(--c-secondary-strong) 30%, transparent);
    border-radius: var(--radius);
    color: var(--c-ink);
}

.ap-alert__icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--c-surface);
    color: var(--c-secondary-strong);
    flex: none;
}

.ap-alert__icon .icon {
    width: 22px;
    height: 22px;
}

.ap-alert p {
    align-self: center;
    line-height: 1.5;
}

.ap-alert strong {
    display: block;
    font-weight: 700;
    color: var(--c-secondary-strong);
}

/* Field groups: numbered, separated by hairlines */
.ap-group {
    min-inline-size: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.ap-group + .ap-group {
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--c-line);
}

.ap-group__title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1) var(--space-3);
    padding: 0;
    font-family: var(--font-serif);
    font-size: 1.3125rem;
    font-weight: 500;
    line-height: 1.25;
    letter-spacing: -0.01em;
    color: var(--c-ink);
}

/* Legend as a plain block: no gap in the group's top rule, normal flow below. */
legend.ap-group__title {
    float: left;
    width: 100%;
}

legend.ap-group__title + * {
    clear: both;
}

.ap-group__num {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--c-sage-soft);
    color: var(--c-teal-strong);
    font-family: var(--font-sans);
    font-size: 0.875rem;
    font-weight: 700;
    flex: none;
}

.ap-optional {
    font-family: var(--font-sans);
    font-size: var(--fs-sm);
    font-weight: 400;
    letter-spacing: 0;
    color: var(--c-ink-soft);
}

.ap-group__note {
    margin: var(--space-1) 0 var(--space-5);
    padding-left: calc(30px + var(--space-3));
    font-size: var(--fs-sm);
    line-height: 1.5;
    color: var(--c-ink-soft);
}

.ap-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5) var(--space-4);
}

.ap-field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
}

.ap-field--full {
    grid-column: 1 / -1;
}

.ap-label {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--c-ink);
}

.ap-input {
    width: 100%;
    min-height: 54px;
    padding: 0.8rem 1.125rem;
    font: inherit;
    font-size: 1.0625rem; /* >= 16px: no zoom on iOS */
    line-height: 1.35;
    color: var(--c-ink);
    background: var(--c-surface);
    border: 1px solid var(--ap-border);
    border-radius: 14px;
    box-shadow: inset 0 1px 2px rgb(11 45 51 / 0.04);
    transition:
        border-color var(--dur) var(--ease-out),
        box-shadow var(--dur) var(--ease-out),
        background-color var(--dur) var(--ease-out);
}

.ap-input::placeholder {
    color: var(--c-ink-soft);
    opacity: 0.7;
}

.ap-input:hover {
    border-color: var(--c-ink-soft);
}

/* Focus: teal edge + soft halo; the transparent outline stays visible in forced colors. */
.ap-input:focus,
.ap-input:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 0;
    border-color: var(--c-teal);
    box-shadow: var(--ap-ring);
}

/* Native validation, only once the person has typed something. */
.ap-input:user-invalid {
    border-color: var(--c-secondary-strong);
}

.ap-textarea {
    min-height: 128px;
    resize: vertical;
}

/* Consultation type: two large radio cards */
.ap-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3);
}

.ap-option {
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: var(--space-3);
    min-height: 80px;
    padding: var(--space-3) var(--space-4) var(--space-3) var(--space-3);
    background: var(--c-surface);
    border: 1px solid var(--ap-border);
    border-radius: var(--radius);
    cursor: pointer;
    transition:
        border-color var(--dur) var(--ease-out),
        background-color var(--dur) var(--ease-out),
        box-shadow var(--dur) var(--ease-out);
}

.ap-option:hover {
    border-color: var(--c-ink-soft);
}

.ap-option .icon-chip {
    width: 48px;
    height: 48px;
}

.ap-option .icon-chip .icon {
    width: 22px;
    height: 22px;
}

.ap-option__text {
    font-size: var(--fs-sm);
    line-height: 1.35;
    color: var(--c-ink-soft);
}

.ap-option__text strong {
    display: block;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--c-ink);
}

/* The radio itself, drawn as a ring on the right of the card. */
.ap-option input {
    grid-column: 3;
    grid-row: 1;
    appearance: none;
    width: 22px;
    height: 22px;
    margin: 0;
    border: 1px solid var(--ap-border);
    border-radius: 50%;
    background: var(--c-surface);
    cursor: pointer;
    transition:
        border-color var(--dur) var(--ease-out),
        box-shadow var(--dur) var(--ease-out);
}

.ap-option input:checked {
    border-color: var(--c-teal);
    box-shadow: inset 0 0 0 5px var(--c-surface), inset 0 0 0 11px var(--c-teal);
}

.ap-option input:focus-visible {
    outline: none;
}

.ap-option:has(input:checked) {
    border-color: var(--c-teal);
    background: color-mix(in srgb, var(--c-teal) 6%, var(--c-surface));
    box-shadow: inset 0 0 0 1px var(--c-teal);
}

.ap-option:has(input:focus-visible) {
    outline: 2px solid transparent;
    border-color: var(--c-teal);
    box-shadow: var(--ap-ring);
}

/* Submit row: button + reassurances */
.ap-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-5) var(--space-6);
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--c-line);
}

.ap-submit {
    min-height: 58px;
    padding-inline: 2.125rem;
    font-size: 1.0625rem;
    border: 0;
}

ul.ap-assure {
    flex: 1 1 15rem;
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ap-assure li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--c-ink-soft);
}

.ap-assure .icon {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    color: var(--c-teal);
}

/* Confirmation state */
.ap-done__icon {
    display: grid;
    place-items: center;
    width: 84px;
    height: 84px;
    margin-bottom: var(--space-5);
    border-radius: 0 50% 0 50%; /* leaf shape from the logo */
    background: linear-gradient(150deg, var(--c-sage-soft), var(--c-mist-soft));
    color: var(--c-teal-strong);
    --icon-duo: var(--c-sage);
    --icon-duo-opacity: 0.5;
}

.ap-done__icon .icon {
    width: 42px;
    height: 42px;
}

.ap-done__subtitle {
    margin: var(--space-6) 0 var(--space-4);
    padding-top: var(--space-6);
    border-top: 1px solid var(--c-line);
    font-family: var(--font-serif);
    font-size: 1.375rem;
    font-weight: 500;
    color: var(--c-ink);
}

ol.ap-done__list {
    display: grid;
    gap: var(--space-4);
    counter-reset: ap-done;
}

ol.ap-done__list > li {
    position: relative;
    padding-left: 2.75rem;
    color: var(--c-ink-soft);
    counter-increment: ap-done;
}

.ap-done__list > li::before {
    content: counter(ap-done);
    position: absolute;
    left: 0;
    top: 0;
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--c-sage-soft);
    color: var(--c-teal-strong);
    font-size: 0.875rem;
    font-weight: 700;
}

.ap-done__list a {
    font-weight: 600;
    color: var(--c-teal-strong);
    white-space: nowrap;
}

.ap-done__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--c-line);
}

/* Compact card (campaign landing, beside the hero title): unnumbered groups without notes, plain
   radio cards, optional message folded away, full-width submit. Same fields and validation. */
.ap-card--compact {
    padding: clamp(1.25rem, 0.9rem + 1.6vw, 2.25rem);
}

.ap-card--compact .ap-card__head {
    margin-bottom: var(--space-5);
}

.ap-card--compact .ap-card__title {
    font-size: clamp(1.625rem, 1.4rem + 0.8vw, 2.125rem);
}

.ap-card--compact .ap-card__intro {
    font-size: var(--fs-sm);
}

.ap-card--compact .ap-group + .ap-group {
    margin-top: var(--space-5);
    padding-top: var(--space-5);
}

.ap-card--compact .ap-group__num {
    display: none;
}

.ap-card--compact .ap-group__title {
    font-size: 1.125rem;
}

/* The contact fields need no heading here (kept for screen readers). */
.ap-card--compact fieldset.ap-group:first-of-type > legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.ap-card--compact .ap-group__note {
    display: none;
}

/* With the note hidden, the options are the first block after the floated legend. */
.ap-card--compact .ap-options {
    clear: both;
}

.ap-card--compact .ap-group__title {
    margin-bottom: var(--space-3);
}

.ap-card--compact .ap-fields {
    gap: var(--space-4);
}

.ap-card--compact .ap-option {
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 60px;
    padding-left: var(--space-4);
}

.ap-card--compact .ap-option .icon-chip {
    display: none;
}

.ap-card--compact .ap-option input {
    grid-column: 2;
}

/* Optional message: a disclosure row (the whole row is the tap target, the caret at its end);
   the textarea opens below. */
.ap-more__toggle {
    display: flex;
    align-items: center;
    gap: var(--space-1) var(--space-2);
    min-height: 48px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--c-teal-strong);
    cursor: pointer;
    list-style: none;
}

.ap-more__toggle::-webkit-details-marker {
    display: none;
}

.ap-more__toggle .icon {
    width: 16px;
    height: 16px;
    margin-left: auto;
    transition: transform var(--dur) var(--ease-out);
}

.ap-more[open] .ap-more__toggle .icon {
    transform: rotate(180deg);
}

/* "(facoltativo)" and the caret wrap together. */
.ap-more__toggle .ap-optional {
    display: flex;
    flex: 1 0 auto;
    align-items: center;
    font-weight: 400;
    white-space: nowrap;
}

.ap-card--compact .ap-more .ap-group__note {
    display: block;
    margin: var(--space-2) 0 var(--space-3);
}

.ap-card--compact .ap-textarea {
    min-height: 96px;
}

.ap-card--compact .ap-actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
    margin-top: var(--space-5);
    padding-top: 0;
    border-top: 0;
}

.ap-card--compact ul.ap-assure {
    flex: none;
}

/* Responsive */
@media (max-width: 767px) {
    .ap-options {
        grid-template-columns: minmax(0, 1fr);
    }

    .ap-alert {
        padding: var(--space-4);
    }

    .ap-submit,
    .ap-done__actions .btn {
        width: 100%;
    }

    .ap-done__actions .btn {
        white-space: normal;
    }
}

@media (max-width: 599px) {
    .ap-fields {
        grid-template-columns: minmax(0, 1fr);
    }

    .ap-group__note {
        padding-left: 0;
    }

    .ap-card__title {
        font-size: 1.625rem;
    }
}

/* Tablet and phone (from 1200px up the rules above apply unchanged). The card is sized by its
   column, so field and option grids follow the card width, not the viewport. */
@media (max-width: 1199px) {
    .ap-card {
        container-type: inline-size;
    }

    /* Email and phone side by side only when both fit the placeholder. */
    @container (max-width: 28rem) {
        .ap-fields {
            grid-template-columns: minmax(0, 1fr);
        }
    }

    /* Radio cards stacked when "in videochiamata" would wrap (sooner with the icon chips). */
    @container (max-width: 31rem) {
        .ap-card:not(.ap-card--compact) .ap-options {
            grid-template-columns: minmax(0, 1fr);
        }
    }

    @container (max-width: 22rem) {
        .ap-options {
            grid-template-columns: minmax(0, 1fr);
        }
    }
}

@media (max-width: 599px) {
    .ap-card__intro {
        font-size: var(--fs-sm);
    }

    .ap-card__head,
    .ap-alert {
        margin-bottom: var(--space-5);
    }

    .ap-group + .ap-group,
    .ap-actions {
        margin-top: var(--space-5);
        padding-top: var(--space-5);
    }

    .ap-group__note {
        margin-bottom: var(--space-4);
    }

    .ap-fields {
        gap: var(--space-4);
    }

    /* Lighter radio cards: same full-card tap area, less height. */
    .ap-option {
        min-height: 64px;
    }

    .ap-option .icon-chip {
        width: 40px;
        height: 40px;
    }

    .ap-option .icon-chip .icon {
        width: 20px;
        height: 20px;
    }

    .ap-assure li {
        font-size: var(--fs-sm);
    }
}

/* Landing on phones: the reassurances under the button already say what the intro says. */
@media (max-width: 599px) {
    .ap-card--compact .ap-card__head {
        margin-bottom: var(--space-4);
    }

    .ap-card--compact .ap-card__head .ap-card__intro {
        display: none;
    }
}
