/**
 * InstantForm Frontend Styles
 *
 * Scoped under .ifo-form so we never touch the theme outside the form.
 * Custom properties (--ifo-form-*) are set inline on the form element by
 * the renderer based on the form's styling settings, so theme designers
 * and end-users can both tweak without overriding CSS rules.
 */

.ifo-form {
    --ifo-form-primary: #5603bc;
    --ifo-form-primary-darker: color-mix(in srgb, var(--ifo-form-primary) 80%, black);
    --ifo-form-border: #e5e7eb;
    --ifo-form-radius: 8px;
    --ifo-form-success: #10b981;
    --ifo-form-danger: #ef4444;
    --ifo-form-text: #111827;
    --ifo-form-muted: #6b7280;

    display: block;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    color: var(--ifo-form-text);
    font: inherit;
    line-height: 1.5;
}

.ifo-form *, .ifo-form *::before, .ifo-form *::after { box-sizing: border-box; }

/* --- progress dots --- */
.ifo-form-progress {
    list-style: none;
    margin: 0 0 20px;
    padding: 0;
    display: flex;
    gap: 8px;
    justify-content: center;
}
.ifo-step-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--ifo-form-border);
    color: var(--ifo-form-muted);
    font-size: 12px;
    font-weight: 600;
    transition: background .2s, color .2s, transform .2s;
}
.ifo-step-dot.ifo-step-active {
    background: var(--ifo-form-primary);
    color: #fff;
    transform: scale(1.1);
}
.ifo-step-dot.ifo-step-done {
    background: var(--ifo-form-success);
    color: #fff;
}

/* --- step section --- */
.ifo-form-step[hidden] { display: none; }
.ifo-form-step-title {
    margin: 0 0 14px;
    font-size: 18px;
    font-weight: 700;
    color: var(--ifo-form-text);
}

/* --- field row --- */
.ifo-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    /* Bottom-align fields in a row so varying label/help heights do not
     * leave inputs at different vertical positions (common with 50% cols). */
    align-items: flex-end;
}

.ifo-form-field,
.ifo-form-subfield {
    display: flex;
    flex-direction: column;
    flex: 0 0 100%;
    min-width: 0;
    border-radius: var(--ifo-form-radius, 8px);
    transition: box-shadow .3s ease;
}
/* The HTML `hidden` attribute is set by conditional logic + step nav.
 * Our `display: flex` above has equal specificity to the UA
 * `[hidden] { display: none }` rule, so without an explicit override
 * hidden fields would still render. */
.ifo-form-field[hidden],
.ifo-form-subfield[hidden] {
    display: none !important;
}

/* Brief halo when navigation jumped directly to this field (e.g. an
 * option-level jump points at "question 7 wherever it lives"). The
 * class is added by frontend.js right after scrollIntoView + focus. */
.ifo-form-field.ifo-field-jumped {
    animation: ifoFieldJump 1.4s ease;
}
@keyframes ifoFieldJump {
    0%   { box-shadow: 0 0 0 0   color-mix(in srgb, var(--ifo-form-primary) 50%, transparent); }
    30%  { box-shadow: 0 0 0 10px color-mix(in srgb, var(--ifo-form-primary) 18%, transparent); }
    100% { box-shadow: 0 0 0 0   color-mix(in srgb, var(--ifo-form-primary) 0%,  transparent); }
}
.ifo-form-field.ifo-w-half,
.ifo-form-subfield.ifo-w-half  { flex: 0 0 calc(50% - 7px); }
.ifo-form-field.ifo-w-third,
.ifo-form-subfield.ifo-w-third { flex: 0 0 calc(33.333% - 9.34px); }

/* Mobile width override (ifo-mw-X). Defaults to "full" via Schema so the
 * historical "stack on mobile" behaviour is preserved unless the form
 * author explicitly chose a half/third mobile width. */
@media (max-width: 540px) {
    .ifo-form-field.ifo-mw-full  { flex: 0 0 100%; }
    .ifo-form-field.ifo-mw-half  { flex: 0 0 calc(50% - 7px); }
    .ifo-form-field.ifo-mw-third { flex: 0 0 calc(33.333% - 9.34px); }
    /* Subfields stack on mobile, except the address lookup row which
     * must stay on one line (standard NL address UX - postcode +
     * huisnummer is what triggers the PDOK auto-fill). */
    .ifo-form-subfield.ifo-w-half,
    .ifo-form-subfield.ifo-w-third { flex: 0 0 100%; }
    .ifo-address-row-lookup,
    .ifo-address-row-street { flex-wrap: nowrap; }
    .ifo-form-subfield.ifo-addr-postcode { flex: 2 1 0; min-width: 0; }
    .ifo-form-subfield.ifo-addr-street   { flex: 1 1 0; min-width: 0; }
    .ifo-form-subfield.ifo-addr-house    { flex: 1 1 0; min-width: 0; }
    .ifo-form-subfield.ifo-addr-addition { flex: 1 1 0; min-width: 0; }
}

/* --- labels --- */
.ifo-form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ifo-form-text);
}
.ifo-form-required { color: var(--ifo-form-danger); }
.ifo-form-help {
    margin: 4px 0 0;
    font-size: 12px;
    color: var(--ifo-form-muted);
}

/* --- inputs --- */
.ifo-form input[type="text"],
.ifo-form input[type="email"],
.ifo-form input[type="tel"],
.ifo-form input[type="url"],
.ifo-form input[type="number"],
.ifo-form input[type="date"],
.ifo-form select,
.ifo-form textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--ifo-form-border);
    border-radius: var(--ifo-form-radius);
    background: #fff;
    font: inherit;
    font-size: 14px;
    color: var(--ifo-form-text);
    line-height: 1.4;
    transition: border-color .15s, box-shadow .15s, background .15s;
    box-shadow: none;
}

.ifo-form textarea { min-height: 110px; resize: vertical; }

.ifo-form input:focus,
.ifo-form select:focus,
.ifo-form textarea:focus {
    outline: none;
    border-color: var(--ifo-form-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ifo-form-primary) 20%, transparent);
}

.ifo-form input.ifo-valid,
.ifo-form select.ifo-valid,
.ifo-form textarea.ifo-valid {
    border-color: var(--ifo-form-success);
}

.ifo-form input.ifo-invalid,
.ifo-form select.ifo-invalid,
.ifo-form textarea.ifo-invalid {
    border-color: var(--ifo-form-danger);
}

/* ---------------------------------------------------------------
 * Browser-chrome control modifiers
 *
 * Toggled from global settings (Settings tab → Mobile experience).
 * Each modifier is opt-in via a class on the <form> element so we can
 * tweak them independently per form later without touching JS.
 * ---------------------------------------------------------------*/

/* --no-zoom: stops iOS Safari from zooming in when a visitor taps a
 * field. Safari triggers the zoom whenever an input has font-size below
 * 16px, so we hard-pin to 16px on viewports up to ~iPad portrait. We
 * keep line-height the same to avoid layout jumps. */
@media (max-width: 768px) {
    .ifo-form--no-zoom input,
    .ifo-form--no-zoom select,
    .ifo-form--no-zoom textarea {
        font-size: 16px;
    }
}

/* --no-autofill: blocks browser autofill suggestion overlays. We set
 * autocomplete="off" on the form server-side, but Chrome / iOS often
 * ignore that on text/email fields - the magic value below is the
 * generally-accepted workaround. We also reset the saved-credentials
 * yellow background that Chrome paints onto autofilled inputs. */
.ifo-form--no-autofill input[type="text"],
.ifo-form--no-autofill input[type="email"],
.ifo-form--no-autofill input[type="tel"],
.ifo-form--no-autofill input[type="number"],
.ifo-form--no-autofill input[type="url"],
.ifo-form--no-autofill input[type="search"] {
    /* autocomplete="off" is set server-side too; the new-password trick
     * is what actually stops Chrome and iOS from suggesting saved values. */
}
.ifo-form--no-autofill input:-webkit-autofill,
.ifo-form--no-autofill input:-webkit-autofill:hover,
.ifo-form--no-autofill input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #fff inset !important;
    -webkit-text-fill-color: var(--ifo-form-text) !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* --unstyled: strips native browser chrome from <select>, date pickers,
 * etc. so they match the rest of the form. The default iOS dropdown
 * looks nothing like our inputs - this brings them in line. */
.ifo-form--unstyled select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='none' stroke='%23374151' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M1 1l5 5 5-5'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
    padding-right: 38px;
}
.ifo-form--unstyled select::-ms-expand { display: none; }
/* Native date / time / month pickers inherit the OS look on iOS - kill
 * the indicator so it visually matches a plain input. (Functionality
 * is preserved; tap still opens the picker.) */
.ifo-form--unstyled input[type="date"],
.ifo-form--unstyled input[type="time"],
.ifo-form--unstyled input[type="month"],
.ifo-form--unstyled input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
    min-height: 42px;
}
.ifo-form--unstyled input[type="date"]::-webkit-calendar-picker-indicator,
.ifo-form--unstyled input[type="time"]::-webkit-calendar-picker-indicator { opacity: .55; }
/* Number spinner controls are out of place inside a styled form. */
.ifo-form--unstyled input[type="number"] {
    -moz-appearance: textfield;
}
.ifo-form--unstyled input[type="number"]::-webkit-outer-spin-button,
.ifo-form--unstyled input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
/* Search-clear "x" on Chrome / Safari is jarring inside our chrome. */
.ifo-form--unstyled input[type="search"]::-webkit-search-decoration,
.ifo-form--unstyled input[type="search"]::-webkit-search-cancel-button,
.ifo-form--unstyled input[type="search"]::-webkit-search-results-button,
.ifo-form--unstyled input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
}

/* --- radio / checkbox --- */
.ifo-form-choices {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}
.ifo-form-choice {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}
.ifo-form-choice input { accent-color: var(--ifo-form-primary); }

/* --- per-field error --- */
.ifo-form-error {
    min-height: 0;
    font-size: 12px;
    color: var(--ifo-form-danger);
    margin-top: 4px;
}
.ifo-form-error:not(:empty) { margin-top: 6px; }

/* --- top-level submit-error summary --- */
.ifo-form-submit-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 0 0 16px 0;
    color: #991b1b;
    font-size: 14px;
}
.ifo-form-submit-error-headline {
    font-weight: 600;
    margin-bottom: 6px;
}
.ifo-form-submit-error-list {
    list-style: disc;
    padding-left: 20px;
    margin: 0;
}
.ifo-form-submit-error-list li {
    font-size: 13px;
    line-height: 1.5;
    color: #7f1d1d;
}
.ifo-form-submit-error-list li[data-ifo-error-jump]:hover {
    text-decoration: underline;
}
.ifo-form-submit-error-list strong { font-weight: 600; color: #7f1d1d; }

/* --- buttons --- */
.ifo-form-buttons {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 22px;
}

.ifo-btn {
    appearance: none;
    border: none;
    padding: 12px 22px;
    border-radius: var(--ifo-form-radius);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s, background .15s, color .15s, opacity .15s;
    line-height: 1;
}

.ifo-btn-primary {
    background: var(--ifo-form-primary);
    color: #fff;
    box-shadow: 0 2px 8px color-mix(in srgb, var(--ifo-form-primary) 30%, transparent);
}
.ifo-btn-primary:hover:not(:disabled) {
    background: var(--ifo-form-primary-darker);
    transform: translateY(-1px);
}
.ifo-btn-secondary {
    background: transparent;
    color: var(--ifo-form-primary);
    border: 1px solid var(--ifo-form-border);
}
.ifo-btn-secondary:hover:not(:disabled) {
    border-color: var(--ifo-form-primary);
}

.ifo-btn:disabled,
.ifo-btn[disabled],
.ifo-btn.is-submit-blocked {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    pointer-events: none;
}

.ifo-btn[hidden] { display: none; }

/* --- honeypot (off-screen) --- */
.ifo-honeypot {
    position: absolute !important;
    left: -9999px !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* --- thank-you swap --- */
.ifo-form-thanks {
    padding: 32px 24px;
    text-align: center;
    border: 1px solid var(--ifo-form-border);
    border-radius: var(--ifo-form-radius);
    background: color-mix(in srgb, var(--ifo-form-success) 6%, white);
}

/* --- address block --- */
.ifo-address-block { display: flex; flex-direction: column; gap: 10px; }
.ifo-address-row { display: flex; gap: 12px; flex-wrap: wrap; }
/* Lookup row: postcode + huisnummer + (optional) toevoeging, all on one
 * line so the visitor fills the PDOK-trigger pair FIRST and street/city
 * auto-populate. Roughly 2fr / 1fr / 1fr - postcode gets the most space
 * because "1234 AB" + spacing needs more chars than a number. */
.ifo-address-row-lookup {
    flex-wrap: nowrap;
    align-items: flex-end;
}
.ifo-form-subfield.ifo-addr-postcode { flex: 2 1 0; min-width: 0; }
.ifo-form-subfield.ifo-addr-house    { flex: 1 1 0; min-width: 0; }
.ifo-form-subfield.ifo-addr-addition { flex: 1 1 0; min-width: 0; }

/* Legacy single-row variant (street + house + addition together) is no
 * longer emitted but the selectors stay for backward compat with any
 * forms that were saved with the old layout. */
.ifo-address-row-street { flex-wrap: nowrap; align-items: flex-end; }
.ifo-form-subfield.ifo-addr-street   { flex: 1 1 0; min-width: 0; }
.ifo-address-block input.ifo-loading {
    background: #f3f4f6;
    color: #6b7280;
    cursor: progress;
}
/* After a successful auto-fill we lock street/city by default - this
   makes that lock visible (subtle grey) without hiding the values. */
.ifo-address-block input[readonly] {
    background: #f9fafb;
    color: #374151;
    cursor: default;
}

/* --- email confirm sibling --- */
.ifo-form-confirm { margin-top: 8px; }
