/*
 * Engine forms: calculator form grid, fields, hints, date picker button. Loaded by layout.html.twig after engine.css,
 * before the site theme (the theme overrides tokens, not these rules).
 *
 * Field markup: .field > label (+ .unit, .optional) / widget / .field-error / .help.
 * In a .form-grid--rows grid every field is a subgrid of four rows (label, widget, error, hint), so fields of one
 * row of the grid stand on one line whatever the length of their labels and hints. Without subgrid support the label
 * keeps a two-line minimum height instead.
 */

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--s-4); align-items: start; }
.form-section { min-width: 0; margin: 0 0 var(--s-2); padding: var(--s-4) 0 0; border: 0; border-top: 1px solid var(--c-border); }
.form-section:first-child, .calc-form > .callout + .form-section { padding-top: 0; border-top: 0; }
.form-section[hidden] { display: none; }
.form-section legend { float: left; width: 100%; margin: 0 0 var(--s-3); padding: 0; font-family: var(--font-display); font-weight: 700; font-size: var(--fs-h3); }
.form-section legend + * { clear: both; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); margin-top: var(--s-2); }
.form-actions button { min-width: 10rem; }

.calc-form .field { min-width: 0; }
.calc-form .field label { display: flex; flex-wrap: nowrap; align-items: baseline; justify-content: space-between; gap: var(--s-2); line-height: 1.3; }
.calc-form .field label .unit { font-weight: 400; color: var(--c-muted); white-space: nowrap; }
/* "optional" is a small grey note at the right end of the label, never a part of the wrapped label text. */
.calc-form .field label .optional { margin-left: auto; flex: none; font-weight: 400; font-size: var(--fs-xs); color: var(--c-muted); white-space: nowrap; }
.calc-form .field input:not([type="checkbox"], [type="radio"]), .calc-form .field select {
    display: block; width: 100%; max-width: 100%; min-height: 46px; padding: 9px 12px;
    border-radius: var(--radius); font-size: 1rem; line-height: 1.3;
}
.calc-form .field select { padding-right: 8px; }
/* 16px keeps iOS from zooming into the field. */
@media (max-width: 767px) { .calc-form .field input, .calc-form .field select { font-size: max(1rem, 16px); } }
.calc-form .field .help { margin: var(--s-1) 0 0; line-height: 1.35; }
.field-error { margin: var(--s-1) 0 0; font-size: var(--fs-sm); font-weight: 600; color: var(--c-error); }
.field--error input, .field--error select { border-color: var(--c-error); }

/* Fallback without subgrid: labels reserve two lines, so inputs of one row still line up for the usual texts. */
:is(.form-grid--rows, .calc-form__row) > .field > label { min-height: 2.6em; }

@supports (grid-template-rows: subgrid) {
    :is(.form-grid--rows, .calc-form__row) > .field { display: grid; grid-row: span 4; grid-template-rows: subgrid; row-gap: 0; align-content: start; }
    :is(.form-grid--rows, .calc-form__row) > .field > label { grid-row: 1; min-height: 0; align-self: end; }
    :is(.form-grid--rows, .calc-form__row) > .field > :not(label, .help, .field-error, .field__error) { grid-row: 2; }
    :is(.form-grid--rows, .calc-form__row) > .field > .field-error, :is(.form-grid--rows, .calc-form__row) > .field > .field__error { grid-row: 3; }
    :is(.form-grid--rows, .calc-form__row) > .field > .help { grid-row: 4; }
}

@media (min-width: 560px) { .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 960px) { .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Date field (date-field.js): the text input stays the main control, the button opens the native picker ---------- */
.date-field { position: relative; display: flex; align-items: stretch; min-width: 0; }
.date-field > input[type="text"] { flex: 1 1 auto; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.date-field__btn {
    flex: none; display: inline-flex; align-items: center; justify-content: center; width: 46px; min-width: 44px; min-height: 44px; padding: 0;
    border: 1px solid var(--c-border-strong); border-left: 0; border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--c-surface); color: var(--c-muted); cursor: pointer;
}
.date-field__btn:hover { color: var(--c-link); background: var(--c-accent-soft); }
.date-field__btn:focus-visible { outline: 2px solid var(--c-focus); outline-offset: -2px; }
.date-field__btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.calc-form .field .date-field__native, .date-field__native { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; min-height: 0; max-width: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.field--error .date-field__btn { border-color: var(--c-error); }
@media print { .date-field__btn, .date-field__native { display: none; } }
