/* field.css — the field lego (web-spec §Forms). Input first, label after:
   every visual state rides sibling combinators — :placeholder-shown =
   resting, :focus = active, :not(:placeholder-shown) = filled — via the
   single-space placeholder sentinel. The FSI is a sibling button, a 1:1
   square on --row-height; the input shortens to accommodate it. The
   tooltip overlays UPWARD (absolute, anchored above) so it paints over
   earlier DOM only — geometry never shifts. Spans unlock under min-width;
   the base declaration IS the narrow render. */

.field {
    position: relative;
    left: 0;
    top: 0;
    display: inline-block;
    width: 100%;                          /* the base case IS the narrow render */
    padding: 0 0 var(--rhythm-large);     /* narrow render breathes a full stage */
    font-size: 16.8px;                    /* elder fallback: the floor */
    font-size: var(--text-base);
    vertical-align: top;
}

/* spans: each column gives up its share of the gutter, and the gutter
   itself lives only BETWEEN adjacent columns — rows land flush on both
   edges by construction, nothing overflows, nothing is clipped */
@media (min-width: 640px) {
    .field { padding-bottom: var(--rhythm-regular); }   /* wide render tightens back */

    .field--half    { width: calc(50% - var(--rhythm-small) / 2); }
    .field--third   { width: calc(33.333% - var(--rhythm-small) * 2 / 3); }
    .field--quarter { width: calc(25% - var(--rhythm-small) * 3 / 4); }

    .field--half + .field--half,
    .field--third + .field--third,
    .field--quarter + .field--quarter { margin-left: var(--rhythm-small); }
}

.field input,
.field select {
    position: relative;
    left: 0;
    top: 0;
    display: inline-block;
    width: 100%;
    height: var(--row-height);
    margin: 0;
    padding: 0 var(--rhythm-tight);
    border: 1px solid var(--color-charcoal);
    border-radius: calc(var(--text-base) * 0.4);
    background-color: var(--color-raise);
    color: var(--color-ink);
    font-family: inherit;
    font-size: 16.8px;                    /* elder fallback: the floor */
    font-size: var(--text-base);
}

.field input {
    padding-right: var(--row-height);   /* interior room: the FSI sits INSIDE the box */
}

/* number inputs: honest type, no spinner chrome — any client (canon, §Forms) */
.field input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}
.field input[type="number"]::-webkit-outer-spin-button,
.field input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.field select {
    appearance: none;
    -webkit-appearance: none;             /* vendor chrome suppressed — the FSI is the affordance */
    padding-right: var(--row-height);   /* interior room: the FSI sits INSIDE the box */
}

/* orange takes the stroke while the lego holds focus */
.field:focus-within input,
.field:focus-within select {
    border-color: var(--color-salmon);
}

.field input:focus,
.field select:focus {
    outline: 2px solid var(--color-salmon);
    outline-offset: -1px;
}

/* ---- the three-state label ----------------------------------------------- */

.field label {
    position: absolute;
    left: var(--rhythm-tight);
    top: calc((var(--row-height) - var(--text-base) * 1.4) / 2);
    width: auto;                          /* content-sized by declaration */
    display: inline-block;
    padding: 0 calc(var(--text-base) * 0.3);
    background-color: transparent;
    color: var(--color-muted);
    line-height: 1.4;
    transition: top 120ms ease, background-color 120ms ease, color 120ms ease;
    pointer-events: none;
}

.field input:focus ~ label,
.field input:not(:placeholder-shown) ~ label,
.field--fixed label {
    top: calc(var(--text-base) * -0.7);
    background-color: var(--color-page);
    border-radius: calc(var(--text-base) * 0.2);
}

.field input:focus ~ label,
.field select:focus ~ label {
    color: var(--color-salmon);
}

.field-label {
    position: relative;
    left: 0;
    top: 0;
    display: inline-block;
    width: auto;                          /* content-sized by declaration */
    font-weight: 600;
}

/* ---- the FSI: sibling button, tri-state, one visible at a time ----------- */

.field-status {
    position: absolute;
    right: var(--rhythm-tight);           /* flush with the input's right edge — inside it */
    top: 0;
    width: var(--row-height);
    height: var(--row-height);
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-muted);
}

.field-status:disabled {
    pointer-events: none;                 /* inert FSI never eats the control's click */
}

.field-status:enabled {
    color: var(--color-salmon);
    cursor: pointer;
}

.field-status:focus-visible {
    outline: 2px solid var(--color-salmon);
    outline-offset: -4px;
}

.field-status .icon {
    --icon-size: var(--row-height);
    --icon-mask-size: var(--icon-glyph);                 /* uniform glyph */
    display: none;
}

.field input:required ~ .field-status .icon--required { display: inline-block; }
.field input:not(:placeholder-shown):invalid ~ .field-status .icon--required { display: none; }
.field input:not(:placeholder-shown):invalid ~ .field-status .icon--error { display: inline-block; }
.field input:not(:placeholder-shown):valid ~ .field-status .icon--required { display: none; }
.field input:not(:placeholder-shown):valid ~ .field-status .icon--complete { display: inline-block; }

/* ---- tooltip: overlay, in situ, anchored ABOVE (paints over earlier DOM) -- */

.field-tooltip {
    position: absolute;
    left: 0;
    bottom: calc(var(--row-height) + var(--rhythm-small));
    width: calc(100% - var(--rhythm-tight));
    padding: var(--rhythm-tight) var(--rhythm-regular);
    background-color: var(--color-ink);
    color: var(--color-page);
    border-radius: calc(var(--text-base) * 0.4);
}

.field-tooltip-heading {
    position: relative;
    left: 0;
    top: 0;
    display: inline-block;
    width: 100%;
    margin: 0 0 var(--rhythm-min);
    font-weight: 600;
}

.field-tooltip-format {
    position: relative;
    left: 0;
    top: 0;
    display: inline-block;
    width: 100%;
    margin: 0;
}

/* ---- select FSI: chevron rests, check confirms (canon, §Forms) ------------
   The open-affordance IS the status indicator. :user-valid flips it to the
   complete state only after the user actually chooses; elder browsers that
   know no :user-valid keep the chevron forever — the conservative truth. */

.field select ~ .field-status .icon--chevron { display: inline-block; }
.field select:user-invalid ~ .field-status .icon--chevron { display: none; }
.field select:user-invalid ~ .field-status .icon--error { display: inline-block; }
.field select:user-valid ~ .field-status .icon--chevron { display: none; }
.field select:user-valid ~ .field-status .icon--complete { display: inline-block; }
