/* ── Forms (revamp F2, F3) ──────────────────────────────────────────────────
   Field anatomy: label above (13px, 500), the control (34px, 8px radius),
   help below (12px, muted), an error under the field. Selects lose the OS
   chevron for the icon set's; date inputs get the calendar icon. */

input, select, textarea, button { font-family: var(--sans); }

.field { display: grid; gap: 6px; min-width: 0; }
.field-label, .field > label:first-child {
    font-size: var(--fs-13);
    font-weight: 500;
    color: var(--text);
}
.field-help { margin: 0; font-size: var(--fs-12); color: var(--text-3); }
.field-error { margin: 0; font-size: var(--fs-12); color: var(--error); }
.field-error[hidden], .field-help[hidden] { display: none; }

/* The control. Applied by class (.control) and to the fields of the shared
   dialog and field components; per-feature inputs keep their own size. */
.control,
.field input:not([type="checkbox"]):not([type="radio"]),
.field select,
.field textarea,
.dialog-field input:not([type="checkbox"]):not([type="radio"]),
.dialog-field select,
.dialog-field textarea {
    width: 100%;
    min-height: var(--control-h);
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: var(--fs-14);
    line-height: 20px;
    box-sizing: border-box;
    transition: border-color var(--dur-med) var(--ease-out), box-shadow var(--dur-med) var(--ease-out);
}
.field textarea, .dialog-field textarea, textarea.control { min-height: 72px; resize: vertical; }
/* A code-like control (tier lines): .control's font: inherit would undo .mono. */
.control.mono { font-family: var(--mono); font-weight: var(--mono-font-weight); font-size: var(--fs-13); }
input[type="search"] { -webkit-appearance: none; appearance: none; }
.control::placeholder, .field ::placeholder, .dialog-field ::placeholder { color: var(--text-3); }

/* Every text-ish control: a visible focus (border + soft halo). */
input:not([type="checkbox"]):not([type="radio"]):focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
    border-color: var(--focus);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
[aria-invalid="true"] { border-color: var(--error) !important; }
/* A read-only control (Settings > Cost settings for every role but
   Administration) reads as a value, not a field to fill: a muted fill and
   no border. The .field selector outranks the shared control rule above;
   the border goes only while not focused, so the focus ring still shows. */
.control[readonly],
.field input[readonly]:not([type="checkbox"]):not([type="radio"]) { background-color: var(--surface-2); color: var(--text-2); cursor: default; }
.control[readonly]:not(:focus-visible),
.field input[readonly]:not(:focus-visible) { border-color: transparent; }

/* F3: custom select, chevron from static/lib/icons.js (via the theme's
   --icon-select-chevron token). */
select:not([multiple]):not([size]) {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 30px;
    background-image: var(--icon-select-chevron);
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 14px 14px;
    cursor: pointer;
}
select:disabled { opacity: 0.55; cursor: not-allowed; }

/* F3: date inputs keep the browser's locale format; the picker button
   becomes the calendar icon. */
input[type="date"], input[type="datetime-local"], input[type="month"] { font-variant-numeric: tabular-nums; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
    width: 14px; height: 14px;
    padding: 2px;
    margin-left: 4px;
    border-radius: var(--radius-xs);
    background: var(--icon-calendar) center / 14px 14px no-repeat;
    color: transparent;
    cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover { background-color: var(--hover); }

/* Checkbox: a 16px square that reads at a glance. */
input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 16px; height: 16px;
    margin: 0;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-xs);
    background: var(--surface);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    vertical-align: middle;
    transition: border-color var(--dur-med), background var(--dur-med);
}
input[type="checkbox"]:hover { border-color: var(--accent); }
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4.5px; top: 1px;
    width: 4px; height: 8px;
    border: solid var(--on-accent);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
input[type="checkbox"]:indeterminate::after {
    content: '';
    position: absolute;
    left: 3px; top: 6px;
    width: 7px; height: 2px;
    background: var(--accent);
}
input[type="checkbox"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; box-shadow: none; }

@media (max-width: 640px) {
    /* DESIGN.md §9: 16px inputs (no iOS zoom), 44px targets. */
    .control, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea,
    .dialog-field input:not([type="checkbox"]):not([type="radio"]), .dialog-field select, .dialog-field textarea {
        font-size: var(--fs-16);
        min-height: var(--touch-target);
    }
}
