/*
    Unified form fields (docs/form-field-markup.md, markup: Views/Shared/_Field.cshtml).
    Layout = a class on the form or any wrapper:
        fld-layout-stacked       label above, bordered box (the default)
        fld-layout-underline     label below, bottom border only
        fld-layout-float-inside  label inside the bordered box, moves to the top of the box
        fld-layout-float-border  label inside the box, moves onto the border (a fieldset/legend opens a gap in the line)
    The site sets the layout on <body> (master.cshtml); a form or section can override it with its own layout class.
    Display mode = is-view on any wrapper. Colours and sizes are the --fld-* variables (defaults on :root); override them on any wrapper (site, dark block).
    The variables follow the site settings (settings.css: --font-family, --input-*, --color-*), with fallbacks, so the
    base colours, font and rounding of a site change the fields too.
    fld-label-up on a field: the label always sits in the "up" position and the placeholder stays visible (masked inputs:
    Cleave / IMask show their mask as placeholder, so "filled" can't be detected from :placeholder-shown).
*/

:root {
    --fld-text: var(--color-text-900, #1d2433);
    --fld-label: var(--color-text-600, #5b6475);
    --fld-muted: var(--color-text-500, #8a92a3);
    --fld-border: var(--input-border-color, #c9ced8);
    --fld-border-hover: var(--color-bg-500, #9aa2b1);
    --fld-focus: var(--color-primary-500, #1e6fd9);
    --fld-focus-ring: color-mix(in srgb, var(--fld-focus) 15%, transparent);
    --fld-error: #d4342c;
    --fld-error-ring: rgba(212, 52, 44, .12);
    --fld-bg: var(--input-bg, #fff);   /* the box */
    --fld-disabled-bg: #f2f4f7;
    --fld-accent: var(--fld-focus);
    --fld-chip: color-mix(in srgb, var(--fld-focus) 12%, var(--fld-bg));   /* multi select chips */
    --fld-valid: #00ca82;      /* the check of fld-show-valid (legacy PurchaseCarFormV3 colour) */
    --fld-valid-size: 20px;
    --fld-valid-space: 30px;   /* room kept free right of the box for the check */
    --fld-valid-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cdefs%3E%3Cmask id='m'%3E%3Crect width='24' height='24' fill='white'/%3E%3Cpath d='M7.6 12.3l3 3 5.8-6.1' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/mask%3E%3C/defs%3E%3Cpolygon mask='url(%23m)' fill='black' stroke='black' stroke-width='1.6' stroke-linejoin='round' points='12,1.6 15.41,3.78 19.35,4.65 20.22,8.59 22.4,12 20.22,15.41 19.35,19.35 15.41,20.22 12,22.4 8.59,20.22 4.65,19.35 3.78,15.41 1.6,12 3.78,8.59 4.65,4.65 8.59,3.78'/%3E%3C/svg%3E");
    --fld-radius: var(--input-border-radius, 6px);
    --fld-h: 48px;             /* box height of single-line fields */
    --fld-pad-x: 14px;
    --fld-font: var(--font-family, inherit);
    --fld-size: 15px;
    --fld-label-size: 14px;
    --fld-label-float: 12px;
    --fld-gap: 18px;           /* between fields in a grid / row */
    --fld-prefix-w: 116px;     /* phone country prefix (flag + "+352") */
}

/* ---------- grid / row ---------- */

.fld-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--fld-gap); }
.fld-grid > .fld-span-full, .fld-grid > .fld-row.fld-span-full, .fld-grid > .fld-check, .fld-grid > .fld-choices { grid-column: 1 / -1; }
@media (max-width: 640px) { .fld-grid { grid-template-columns: minmax(0, 1fr); } }

/* fields in the site grid (row > col): the columns give the side gutter, the field the space below */
.row > [class*="col"] > .fld, .row > [class*="col"] > .fld-row { margin-bottom: var(--fld-gap); }

/* fields under each other (popups, one-column forms); margins, not a flex gap, so a container that sets its own
   display (the form steps) keeps the spacing. Hidden inputs (honeypots, ids) take no space. */
.fld-stack > :not(input[type=hidden], .hp) { margin-bottom: var(--fld-gap); }
.fld-stack > :last-child { margin-bottom: 0; }

.fld-row { display: flex; gap: var(--fld-gap); align-items: flex-start; }
.fld-row > .fld { flex: 1 1 0; min-width: 0; }
.fld-row > .fld-size-s { flex: 0 0 32%; }
.fld-row > .fld-size-m { flex: 0 0 50%; }

/* ---------- the field ---------- */

/* padding is inside every height (inputs default to content-box, selects to border-box), so all controls in a layout are equally high */
.fld, .fld *, .fld *::before, .fld *::after { box-sizing: border-box; }

.fld {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
    font-family: var(--fld-font);
    color: var(--fld-text);
}

.fld-label {
    display: block;
    font-size: var(--fld-label-size);
    font-weight: 500;
    line-height: 1.3;
    color: var(--fld-label);
}
.fld.is-required > .fld-label::after, .fld.is-required > legend.fld-label::after { content: " *"; color: var(--fld-error); }

.fld-box {
    position: relative;
    display: flex;
    align-items: center;
    min-height: var(--fld-h);
    border: 1px solid var(--fld-border);
    border-radius: var(--fld-radius);
    background: var(--fld-bg);
    transition: border-color .15s, box-shadow .15s;
}
.fld-box:hover { border-color: var(--fld-border-hover); }
.fld-box:focus-within { border-color: var(--fld-focus); box-shadow: 0 0 0 3px var(--fld-focus-ring); }

.fld-box > .fld-input,
.fld-box > textarea.fld-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: calc(var(--fld-h) - 2px);
    margin: 0;
    padding: 0 var(--fld-pad-x);
    border: 0;
    border-radius: var(--fld-radius);
    outline: 0;
    background: transparent;
    box-shadow: none;
    font: inherit;
    font-size: var(--fld-size);
    color: var(--fld-text);
    -webkit-appearance: none;
    appearance: none;
}
.fld-box > textarea.fld-input { height: auto; min-height: 110px; padding-top: 12px; padding-bottom: 12px; resize: vertical; line-height: 1.45; }
.fld-box > select.fld-input:not([multiple]) {
    padding-right: 36px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235b6475' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 14px center;
}
.fld-box > .fld-input::placeholder { color: transparent; }

.fld-affix { flex: 0 0 auto; padding: 0 var(--fld-pad-x); font-size: var(--fld-size); color: var(--fld-muted); white-space: nowrap; }
.fld.has-prefix .fld-box > .fld-input { padding-left: 0; }
.fld.has-suffix .fld-box > .fld-input { padding-right: 0; }

.fld-value { display: none; font-size: var(--fld-size); line-height: 1.45; min-height: 1.45em; word-break: break-word; }
.fld-hint { font-size: 13px; color: var(--fld-muted); line-height: 1.35; }
.fld-msg { font-size: 13px; color: var(--fld-error); line-height: 1.35; }
.fld-msg:empty { display: none; }

/* states */
.fld.is-invalid .fld-box { border-color: var(--fld-error); }
.fld.is-invalid .fld-box:focus-within { box-shadow: 0 0 0 3px var(--fld-error-ring); }
.fld.is-invalid > .fld-label { color: var(--fld-error); }
.fld.is-disabled .fld-box { background: var(--fld-disabled-bg); }
.fld.is-disabled .fld-box:hover { border-color: var(--fld-border); }
.fld.is-disabled .fld-input { color: var(--fld-muted); cursor: not-allowed; }

/* valid check: opt-in with fld-show-valid on the form or any wrapper. The boxed fields keep room on their
   right for it (also while empty, so nothing shifts), the check appears there once the field is filled in correctly. */
.fld-show-valid .fld-boxed > .fld-box { margin-right: var(--fld-valid-space); }
.fld-show-valid .fld-boxed > .fld-box::after {
    content: "";
    position: absolute;
    top: 50%;
    right: calc(-1 * var(--fld-valid-space) + (var(--fld-valid-space) - var(--fld-valid-size)) / 2 - 1px);
    width: var(--fld-valid-size);
    height: var(--fld-valid-size);
    margin-top: calc(var(--fld-valid-size) / -2);
    background: var(--fld-valid);
    -webkit-mask: var(--fld-valid-icon) no-repeat center / contain;
    mask: var(--fld-valid-icon) no-repeat center / contain;
    opacity: 0;
    transform: scale(.6);
    transition: opacity .15s, transform .15s;
    pointer-events: none;
}
.fld-show-valid .fld-boxed.is-valid > .fld-box::after { opacity: 1; transform: none; }
.fld-show-valid .fld-textarea > .fld-box::after { top: 24px; }

/* fld-label-hidden: the label only for screen readers (a radio list under a section title that already says it) */
.fld-label-hidden > .fld-label { position: absolute !important; width: 1px; height: 1px; margin: 0; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* honeypots stay out of sight */
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

/* ---------- select2 inside the box ---------- */

.fld-box > .select2-container { flex: 1 1 auto; min-width: 0; width: 100% !important; }
.fld-box .select2-container .select2-selection {
    display: flex;
    align-items: center;
    min-height: calc(var(--fld-h) - 2px);
    height: auto;
    border: 0;
    border-radius: var(--fld-radius);
    background: transparent;
    outline: 0;
}
.fld-box .select2-container--default .select2-selection--single .select2-selection__rendered {
    padding: 0 36px 0 var(--fld-pad-x);
    line-height: 1.4;
    font-size: var(--fld-size);
    color: var(--fld-text);
}
.fld-box .select2-container--default .select2-selection--single .select2-selection__arrow { top: 50%; right: 10px; height: 20px; transform: translateY(-50%); }
.fld-box .select2-container--default .select2-selection--single .select2-selection__rendered { flex: 1 1 auto; min-width: 0; }   /* full width, so the clear button floats to the right */
.fld-box .select2-container--default .select2-selection--single .select2-selection__clear { margin-right: 6px; color: var(--fld-muted); }
.fld-box .select2-container--default .select2-selection--multiple { padding: 6px calc(var(--fld-pad-x) - 5px); cursor: text; }
.fld-box .select2-container--default .select2-selection--multiple .select2-selection__rendered { display: flex; flex-wrap: wrap; gap: 5px; padding: 0; margin: 0; }
.fld-box .select2-container--default .select2-selection--multiple .select2-selection__choice {
    margin: 0;
    padding: 3px 8px;
    border: 0;
    border-radius: 4px;
    background: var(--fld-chip);
    color: var(--fld-text);
    font-size: 13px;
}
.fld-box .select2-container--default .select2-search--inline .select2-search__field { margin: 0; min-height: 26px; font: inherit; font-size: var(--fld-size); }

/* the dropdown opens inside the .fld (dropdownParent), so it inherits the field variables */
.fld .select2-dropdown { border: 1px solid var(--fld-border); border-radius: var(--fld-radius); box-shadow: 0 8px 24px rgba(16, 24, 40, .12); overflow: hidden; font-size: var(--fld-size); z-index: 20; }
.fld .select2-container--open .select2-dropdown--below { margin-top: 4px; }
.fld .select2-container--open .select2-dropdown--above { margin-top: -4px; }
.fld .select2-results__option { padding: 8px var(--fld-pad-x); }
.fld .select2-container--default .select2-results__option--highlighted[aria-selected] { background: var(--fld-focus); }
.fld .select2-search--dropdown .select2-search__field { border: 1px solid var(--fld-border); border-radius: 4px; padding: 6px 8px; }

/* ---------- phone: prefix select + number in one box ---------- */

.fld-phone .fld-box > select.fld-prefix,
.fld-phone .fld-box > .select2-container:first-of-type { flex: 0 0 var(--fld-prefix-w); width: var(--fld-prefix-w) !important; }
.fld-phone .fld-box > .select2-container:first-of-type { border-right: 1px solid var(--fld-border); border-radius: var(--fld-radius) 0 0 var(--fld-radius); }
.fld-phone .fld-box > .select2-container:first-of-type .select2-selection__rendered { padding-right: 26px; padding-left: 12px; }
.fld-phone .fld-box > select.fld-prefix { border-right: 1px solid var(--fld-border); border-radius: var(--fld-radius) 0 0 var(--fld-radius); }
.fld-phone .fld-box > input.fld-input { padding-left: 12px; }
.fld-phone .select2-dropdown { min-width: 120px; }
.fld-flag { display: inline-flex; align-items: center; gap: 8px; }
.fld-flag .flag-icon { width: 20px; height: 15px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .08); }

/* ---------- input with an action button / spinner ---------- */

.fld-action { flex: 0 0 auto; align-self: stretch; padding: 0 var(--fld-pad-x); border: 0; border-left: 1px solid var(--fld-border); background: transparent; color: var(--fld-label); cursor: pointer; border-radius: 0 var(--fld-radius) var(--fld-radius) 0; }
.fld-action:hover { color: var(--fld-focus); }
.fld-spinner { flex: 0 0 auto; padding: 0 10px; color: var(--fld-muted); }
.fld-spinner[hidden] { display: none; }

/* a lookup: a field with a results list under it (company search); the list is shown by the form script */
.fld-lookup { position: relative; }
.fld-lookup > .fld-results {
    display: none;
    position: absolute;
    z-index: 20;
    top: calc(var(--fld-h) + 4px);
    left: 0;
    right: 0;
    padding: 5px;
    border: 1px solid var(--fld-border);
    border-radius: var(--fld-radius);
    background: var(--fld-bg);
    box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
}
.fld-layout-float-inside .fld-lookup > .fld-results { top: 60px; }
.fld-results a { display: block; padding: 6px 8px; border-radius: 4px; font-size: 13px; line-height: 20px; color: var(--fld-text); text-decoration: none; }
.fld-results a:hover { background: var(--fld-chip); }
.fld-results a strong { display: block; font-size: 15px; line-height: 20px; }

/* ---------- layout 1: stacked (default) ---------- */
/* label above the box: the base styles already do this */

/* ---------- layout 2: underline, label below ---------- */

.fld-layout-underline .fld-boxed > .fld-label { order: 2; font-size: var(--fld-label-float); text-transform: uppercase; letter-spacing: .04em; }
.fld-layout-underline .fld-boxed > .fld-box { order: 1; border-width: 0 0 1px; border-radius: 0; background: transparent; }
.fld-layout-underline .fld-boxed > .fld-box:focus-within { box-shadow: 0 1px 0 0 var(--fld-focus); }
.fld-layout-underline .fld-boxed.is-invalid > .fld-box:focus-within { box-shadow: 0 1px 0 0 var(--fld-error); }
.fld-layout-underline .fld-boxed > .fld-value { order: 1; }
.fld-layout-underline .fld-boxed > .fld-hint { order: 3; }
.fld-layout-underline .fld-boxed > .fld-msg { order: 4; }
.fld-layout-underline .fld-boxed { gap: 4px; }
.fld-layout-underline .fld-boxed .fld-box > .fld-input,
.fld-layout-underline .fld-boxed .fld-box .select2-selection__rendered,
.fld-layout-underline .fld-boxed .fld-box .select2-selection--multiple { padding-left: 0; }
.fld-layout-underline .fld-boxed.has-prefix .fld-affix:first-child { padding-left: 0; }
.fld-layout-underline .fld-phone .fld-box > .select2-container:first-of-type,
.fld-layout-underline .fld-phone .fld-box > select.fld-prefix { border-right: 0; }
.fld-layout-underline .fld-phone .fld-box > input.fld-input { padding-left: 8px; }
.fld-layout-underline .fld-box .fld-action { border-left: 0; }

/* ---------- layouts 3 + 4: floating label ---------- */
/* The label is out of the flow and lies over the box (the box is the first thing in the field).
   It rests in the middle of the box and moves up when the field has focus or a value. */

:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-boxed > .fld-label {
    position: absolute;
    z-index: 2;
    top: calc(var(--fld-h) / 2);
    left: calc(var(--fld-pad-x) + 1px);
    max-width: calc(100% - 2 * var(--fld-pad-x) - 24px);
    transform: translateY(-50%);
    font-size: var(--fld-size);
    font-weight: 400;
    color: var(--fld-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    transition: top .15s, transform .15s, font-size .15s, color .15s;
}
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-textarea > .fld-label { top: 23px; }
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-phone > .fld-label { left: calc(var(--fld-prefix-w) + 13px); }
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-boxed.has-prefix > .fld-label { left: calc(var(--fld-pad-x) + 2.2em); }

/* the "up" state */
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-boxed:is(:focus-within, .is-filled, :has(.fld-box > :is(input, textarea).fld-input:not(:placeholder-shown)), :has(.fld-input:autofill)) > .fld-label {
    font-size: var(--fld-label-float);
    font-weight: 500;
    color: var(--fld-label);
}
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-boxed:focus-within > .fld-label { color: var(--fld-focus); }
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-boxed.is-invalid > .fld-label { color: var(--fld-error); }

/* fld-label-up: masked inputs show their mask as placeholder, so the label stays up and the placeholder visible */
.fld-label-up .fld-box > .fld-input::placeholder { color: var(--fld-muted); opacity: .7; }
:is(.fld-layout-float-inside, .fld-layout-float-border) .fld-boxed.fld-label-up > .fld-label { font-size: var(--fld-label-float); font-weight: 500; color: var(--fld-label); }
.fld-layout-float-inside .fld-boxed.fld-label-up > .fld-label { top: 9px; transform: none; }
.fld-layout-float-border .fld-boxed.fld-label-up > .fld-label { top: 1px; }
.fld-layout-float-border .fld-boxed.fld-label-up .fld-outline > legend { max-width: 100%; }

/* 3: float inside: the label moves to the top of the box, the value sits lower */
.fld-layout-float-inside .fld-boxed { --fld-h: 56px; }
.fld-layout-float-inside .fld-boxed:is(:focus-within, .is-filled, :has(.fld-box > :is(input, textarea).fld-input:not(:placeholder-shown)), :has(.fld-input:autofill)) > .fld-label { top: 9px; transform: none; }
.fld-layout-float-inside .fld-boxed.has-prefix:is(:focus-within, .is-filled, :has(.fld-box > input.fld-input:not(:placeholder-shown))) > .fld-label { left: calc(var(--fld-pad-x) + 1px); }
.fld-layout-float-inside .fld-boxed .fld-box > input.fld-input,
.fld-layout-float-inside .fld-boxed .fld-box > select.fld-input:not([multiple]) { padding-top: 18px; }
.fld-layout-float-inside .fld-boxed .fld-box > textarea.fld-input { padding-top: 28px; }
.fld-layout-float-inside .fld-boxed .fld-box > .select2-container .select2-selection--single .select2-selection__rendered { padding-top: 18px; }
.fld-layout-float-inside .fld-boxed .fld-box > .select2-container .select2-selection--multiple { padding-top: 26px; }
.fld-layout-float-inside .fld-boxed .fld-box > .fld-affix { padding-top: 18px; }
/* the phone prefix keeps its flag centred */
.fld-layout-float-inside .fld-phone .fld-box > .select2-container:first-of-type .select2-selection__rendered,
.fld-layout-float-inside .fld-phone .fld-box > select.fld-prefix { padding-top: 0; }

/* 4: float on the border. The border is drawn by the aria-hidden fieldset.fld-outline inside the box: its legend
   (a hidden copy of the label) opens a real gap in the line, like a native fieldset, so it works on any background.
   The legend is 0 wide while the label rests and opens to the label's width when it floats. */
.fld-layout-float-border .fld-boxed > .fld-box { border-color: transparent; }
.fld-layout-float-border .fld-boxed > .fld-box:focus-within { box-shadow: none; }
.fld-layout-float-border .fld-boxed:is(:focus-within, .is-filled, :has(.fld-box > :is(input, textarea).fld-input:not(:placeholder-shown)), :has(.fld-input:autofill)) > .fld-label { top: 1px; left: calc(var(--fld-pad-x) + 1px); }
.fld-layout-float-border .fld-outline {
    display: block;
    position: absolute;
    inset: -5px -1px -1px -1px;   /* over the box border; the top is raised by half the legend height */
    margin: 0;
    padding: 0 0 0 calc(var(--fld-pad-x) - 4px);
    min-width: 0;
    border: 1px solid var(--fld-border);
    border-radius: var(--fld-radius);
    pointer-events: none;
    text-align: left;
    transition: border-color .15s;
}
.fld-layout-float-border .fld-outline > legend {
    display: block;
    float: none;
    width: auto;
    max-width: .01px;
    height: 10px;
    padding: 0;
    overflow: hidden;
    visibility: hidden;
    white-space: nowrap;
    font-size: var(--fld-label-float);
    font-weight: 500;
    line-height: 10px;
    transition: max-width .1s;
}
.fld-layout-float-border .fld-outline > legend > span { display: inline-block; padding: 0 4px; }
.fld-layout-float-border .fld-boxed.is-required .fld-outline > legend > span::after { content: " *"; }
.fld-layout-float-border .fld-boxed:is(:focus-within, .is-filled, :has(.fld-box > :is(input, textarea).fld-input:not(:placeholder-shown)), :has(.fld-input:autofill)) .fld-outline > legend { max-width: 100%; transition: max-width .05s .05s; }
.fld-layout-float-border .fld-boxed > .fld-box:hover > .fld-outline { border-color: var(--fld-border-hover); }
.fld-layout-float-border .fld-boxed > .fld-box:focus-within > .fld-outline { border-color: var(--fld-focus); border-width: 2px; padding-left: calc(var(--fld-pad-x) - 5px); }
.fld-layout-float-border .fld-boxed.is-invalid > .fld-box > .fld-outline { border-color: var(--fld-error); }
.fld-layout-float-border .fld-boxed.is-disabled > .fld-box:hover > .fld-outline { border-color: var(--fld-border); }
.fld-layout-float-border .fld-phone .fld-box > .select2-container:first-of-type,
.fld-layout-float-border .fld-phone .fld-box > select.fld-prefix,
.fld-layout-float-border .fld-box .fld-action { border-color: var(--fld-border); }
.fld-outline { display: none; }

/* ---------- checkbox / switch ---------- */

.fld-check { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 0 10px; }
.fld-check > .fld-input,
.fld-option > input {
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    margin: 1px 0 0;
    border: 1px solid var(--fld-border);
    border-radius: 4px;
    background: var(--fld-bg) no-repeat center / 12px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: background-color .15s, border-color .15s;
}
.fld-check > .fld-input:checked,
.fld-option > input[type=checkbox]:checked {
    border-color: var(--fld-accent);
    background-color: var(--fld-accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 10'%3E%3Cpath d='M1 5l3.5 3.5L11 1.5' fill='none' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E");
}
.fld-option > input[type=radio] { border-radius: 50%; }
.fld-option > input[type=radio]:checked { border: 6px solid var(--fld-accent); }
.fld-check > .fld-input:focus-visible, .fld-option > input:focus-visible { outline: 0; box-shadow: 0 0 0 3px var(--fld-focus-ring); }
.fld-check > .fld-label { flex: 1 1 0; min-width: 0; font-size: var(--fld-size); font-weight: 400; color: var(--fld-text); cursor: pointer; }
.fld-check.is-required > .fld-label::after { content: none; }
.fld-check > .fld-label a { color: var(--fld-focus); }
.fld-label-info { display: block; margin-top: 2px; font-size: 13px; color: var(--fld-muted); }
.fld-check > .fld-value, .fld-check > .fld-msg { flex: 0 0 100%; padding-left: 30px; }
.fld-check.is-invalid > .fld-input { border-color: var(--fld-error); box-shadow: 0 0 0 3px var(--fld-error-ring); }

.fld-switch > .fld-input { width: 40px; height: 22px; border-radius: 11px; background: var(--fld-border); border-color: var(--fld-border); position: relative; }
.fld-switch > .fld-input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
.fld-switch > .fld-input:checked { background-image: none; }
.fld-switch > .fld-input:checked::after { transform: translateX(18px); }
.fld-switch > .fld-value, .fld-switch > .fld-msg { padding-left: 50px; }

/* ---------- radio / checkbox lists ---------- */

.fld-choices > legend.fld-label { float: left; width: 100%; margin-bottom: 8px; padding: 0; }
.fld-choices > legend.fld-label + * { clear: both; }
.fld-options { display: flex; flex-direction: column; gap: 10px; }
.fld-options-inline { flex-direction: row; flex-wrap: wrap; gap: 10px 24px; }
.fld-option { display: flex; align-items: flex-start; gap: 10px; }
.fld-option > label { font-size: var(--fld-size); cursor: pointer; }
.fld-choices.is-invalid .fld-option > input { border-color: var(--fld-error); }

/* pills: the options as a segmented button */
.fld-options-pills { flex-direction: row; flex-wrap: wrap; gap: 0; }
.fld-options-pills .fld-option { position: relative; gap: 0; }
.fld-options-pills .fld-option > input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.fld-options-pills .fld-option > label {
    display: block;
    padding: 10px 18px;
    border: 1px solid var(--fld-border);
    margin-left: -1px;
    background: var(--fld-bg);
    color: var(--fld-label);
    transition: background-color .15s, color .15s;
}
.fld-options-pills .fld-option:first-child > label { margin-left: 0; border-radius: var(--fld-radius) 0 0 var(--fld-radius); }
.fld-options-pills .fld-option:last-child > label { border-radius: 0 var(--fld-radius) var(--fld-radius) 0; }
.fld-options-pills .fld-option > input:checked + label { position: relative; z-index: 1; border-color: var(--fld-accent); background: var(--fld-accent); color: #fff; }
.fld-options-pills .fld-option > input:focus-visible + label { box-shadow: 0 0 0 3px var(--fld-focus-ring); }

/* ---------- file ---------- */

.fld-file .fld-box { min-height: 96px; justify-content: center; border-style: dashed; cursor: pointer; overflow: hidden; }
.fld-file .fld-box > .fld-input { position: absolute; inset: 0; height: 100%; opacity: 0; cursor: pointer; z-index: 1; padding: 0; }
.fld-file .fld-file-text { display: inline-flex; align-items: center; gap: 8px; padding: 0 var(--fld-pad-x); color: var(--fld-label); font-size: 14px; text-align: center; }
.fld-file .fld-file-preview { max-height: 80px; margin: 8px; border-radius: 4px; }
.fld-file.is-dragover .fld-box, .fld-file .fld-box:focus-within { border-color: var(--fld-focus); background: #f5f8ff; }

/* ---------- range: two sliders on one track ---------- */

.fld-range .fld-box { flex-direction: column; align-items: stretch; gap: 6px; min-height: 0; padding: 14px var(--fld-pad-x) 10px; }
.fld-range-track { position: relative; height: 22px; }
.fld-range-track::before { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 4px; margin-top: -2px; border-radius: 2px; background: linear-gradient(to right, var(--fld-border) var(--from, 0%), var(--fld-accent) var(--from, 0%), var(--fld-accent) var(--to, 100%), var(--fld-border) var(--to, 100%)); }
.fld-range-track > .fld-input { position: absolute; inset: 0; width: 100%; height: 22px; margin: 0; padding: 0; background: transparent; pointer-events: none; -webkit-appearance: none; appearance: none; }
.fld-range-track > .fld-input::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 20px; height: 20px; border: 2px solid var(--fld-accent); border-radius: 50%; background: #fff; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.fld-range-track > .fld-input::-moz-range-thumb { pointer-events: auto; width: 16px; height: 16px; border: 2px solid var(--fld-accent); border-radius: 50%; background: #fff; cursor: pointer; }
.fld-range-track > .fld-input::-moz-range-track { background: transparent; }
.fld-range-track > .fld-input:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--fld-focus-ring); }
.fld-range-values { display: flex; justify-content: space-between; font-size: 14px; color: var(--fld-label); }

/* ---------- display mode ---------- */

.fld:not(.is-static) > .fld-value { display: none; }
.fld.is-static > .fld-box, .fld.is-static > .fld-hint { display: none; }
.fld.is-static > .fld-value { display: block; }

.is-view .fld > .fld-box,
.is-view .fld > .fld-hint,
.is-view .fld > .fld-msg,
.is-view .fld-check > .fld-input,
.is-view .fld-choices > .fld-options { display: none; }
.is-view .fld > .fld-value { display: block; }
.is-view .fld-check > .fld-value, .is-view .fld-switch > .fld-value { padding-left: 0; }
/* display mode wins over every layout, also over the floating "up" state of filled fields */
.is-view .fld:not(.fld-check) > .fld-label,
.fld.is-static > .fld-label {
    position: static !important;
    order: 0 !important;
    transform: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
    font-size: var(--fld-label-float) !important;
    font-weight: 500;
    color: var(--fld-muted) !important;
    text-transform: none;
    letter-spacing: 0;
    max-width: none;
}
.is-view .fld > .fld-label::after { content: none; }
.is-view .fld-check > .fld-label { flex-basis: 100%; font-size: var(--fld-label-float); font-weight: 500; color: var(--fld-muted); cursor: default; }
.is-view .fld-value:empty::before { content: "–"; color: var(--fld-muted); }
