/* WIDGETS */
/* input[type="search"] skips the inputs Choices.js owns — it builds its search box as
   input[type="search"].choices__input, which must stay borderless inside .choices__inner
   (see choices-override.css). The guard is wrapped in :where() so it contributes zero
   specificity: the whole :is() list stays at (0,1,1) and the .tt-valid/.tt-invalid rules
   further down still win on source order. Mirrored in form-widgets.css for input groups. */
.tt-form :is(input[type="text"], input[type="tel"], input[type="email"],
             input[type="number"], input[type="date"], input[type="time"],
             input[type="password"], input[type="file"],
             input[type="search"]:where(:not(.choices__input)), select),
.tt-form-input {
    background-color: var(--bg-color);
    border: var(--border-thin) solid currentColor;
    max-width: 100%;
    width: 100%;
    padding: var(--form-input-padding);
    color: inherit;
    line-height: normal;
    height: var(--form-input-height);
    box-sizing: border-box;
    font-size: var(--form-input-font-size);
}

.tt-form textarea {
    background-color: var(--bg-color);
    border: var(--border-thin) solid currentColor;
    max-width: 100%;
    width: 100%;
    padding: var(--form-input-padding);
    color: inherit;
    line-height: normal;
    box-sizing: border-box;
    font-size: var(--form-input-font-size);
    resize: vertical;
}

/* Standalone .tt-form-input outside a scoping class needs an explicit color
   since form controls opt out of color inheritance by default */
.tt-form-input {
    color: var(--paragraph-color);
}

/* PLACEHOLDER */
.tt-form input::placeholder,
.tt-form-input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* AUTOFILL — browsers override font-size via :-webkit-autofill; restore it explicitly */
.tt-form :is(input[type="text"], input[type="email"], input[type="password"],
             input[type="tel"], input[type="number"]):-webkit-autofill,
.tt-form-input:-webkit-autofill {
    font-size: var(--form-input-font-size);
}

/* RADIO WIDGET */
.radio-group {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--space-2xs);
    align-items: center;
}

.radio-group label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3xs);
}

/* FILE WIDGET */
.tt-form input[type="file"] {
    cursor: pointer;
}

/* Hide the default file upload button (optional) */
.tt-form input[type="file"]::-webkit-file-upload-button {
    visibility: hidden;
}

/* Firefox */
.tt-form input[type="file"]::file-selector-button {
    visibility: hidden;
}

.tt-form input[type="checkbox"],
.tt-form-input-checkbox {
    appearance: none;
    position: relative;
    width: var(--step-0);
    height: var(--step-0);
    color: inherit;
    border: var(--border-thin) solid currentColor;
    line-height: 1;
    background: var(--bg-color);
    margin-right: var(--space-3xs);
}

.tt-form input, .tt-form select, .tt-form textarea {
    border-radius: var(--input-border-radius);
}

.tt-form input[type="checkbox"]::before,
.tt-form-input-checkbox::before {
    position: absolute;
    width: 100%;
    height: 100%;
    text-align: center;
    white-space: pre;
    content: " ";
}

.tt-form input[type="checkbox"]:checked::before,
.tt-form-input-checkbox:checked::before {
    content: "\2713";
    color: var(--primary-color);
    padding-top: 2px;
}

.tt-form input[type="checkbox"]:indeterminate::before,
.tt-form-input-checkbox:indeterminate::before {
    content: "–";
    color: var(--primary-color);
    padding-top: 2px;
}

/* FOCUS */
.tt-form input:focus, .tt-form-input:focus,
.tt-form select:focus, .tt-form-select:focus, .tt-form .tt-form-row select:focus,
.tt-form textarea:focus,
.tt-form-input-checkbox:focus {
    border-color: var(--primary-color);
}

/* Focus ring for the text-entry controls. Without one they fall back to the UA ring,
   outline-style: auto — a fixed browser blue that is off-brand in light theme and
   clashes with the orange primary in dark. (auto also can't follow border-radius,
   which is what makes it read as wrong inside an input group — see the FOCUS note in
   form-widgets.css.)

   Geometry: a negative outline-offset paints the band from (offset - width) to
   (offset), measured inward from the border edge — so the offset magnitude must be at
   least the width or the ring spills outside the control and onto its neighbour.
   Keeping them equal pins the ring to the outermost 2px of the box, growing inward.

   Checkboxes, radios and buttons deliberately stay on the UA ring: an inset edge is
   wrong for all three, and choosing their treatment is a design decision rather than
   a port of this one. */
.tt-form :is(input[type="text"], input[type="tel"], input[type="email"],
             input[type="number"], input[type="date"], input[type="time"],
             input[type="password"], select, textarea,
             input[type="search"]:where(:not(.choices__input))):focus,
.tt-form-input:focus,
.tt-form-select:focus {
    outline: var(--border-md) solid var(--primary-color);
    outline-offset: calc(var(--border-md) * -1);
}

/* DISABLED */
.tt-form input:disabled,
.tt-form select:disabled {
    border: var(--border-thin) solid var(--text-muted);
    appearance: none;
    background-color: var(--bg-muted);
    color: var(--text-color);
}

/* VALIDATION — the same thick inner left edge as a field that differs from the plan;
   --form-input-padding-inline leaves room for it. */
.tt-form input.tt-invalid,
.tt-form select.tt-invalid {
    border: var(--border-thin) solid var(--danger-color);
    box-shadow: inset var(--border-thick) 0 0 var(--danger-color);
}

.tt-form input.tt-valid,
.tt-form select.tt-valid {
    border: var(--border-thin) solid var(--success-color);
    box-shadow: inset var(--border-thick) 0 0 var(--success-color);
}

.tt-form .tt-required span {
    color: var(--danger-color);
}

/* Standalone required-indicator star, for fields whose "required" state toggles live
   (e.g. with the personalia form's "invoicing only" checkbox) rather than being baked
   into label_attr at render time. It renders as a sibling after form_label()'s <label>
   rather than inside it, so without this wrapper it would drop to its own line — labels
   are width:100% by default (see LABEL rules above). */
.tt-form .tt-label-with-star {
    display: flex;
    align-items: baseline;
    gap: var(--space-3xs);
}

.tt-form .tt-label-with-star label,
.tt-form .tt-label-with-star .tt-label {
    width: auto;
}

.tt-form .tt-label-header label,
.tt-form .tt-label-header .tt-label,
.tt-label.tt-label-header {
    font-weight: bold;
}

.tt-form .tt-required-star {
    color: var(--danger-color);
}

/* BUTTONS */
.tt-form .tt-btn-primary {
    width: 100%;
}

/* FORM ERRORS */
.tt-form-error-list {
    list-style: none;
    margin: 0 0 0 var(--space-3xs);
    padding: 0;
    font-size: 0.875rem; /* slightly smaller text */
    color: var(--danger-color);
}

.tt-form-error {
    margin: 0;
    padding: 0;
}

/* FORM HELPER TEXT — same formatting as .tt-form-error-list, without the danger color */
.tt-form-helper {
    margin: 0 0 0 var(--space-3xs);
    padding: 0;
    font-size: 0.875rem; /* slightly smaller text */
    color: var(--form-label-color);
}

/* A helper line that leads with an icon. The icon hangs beside the text rather
   than sitting inside its first line, so a wrapped second line stays aligned
   with the first instead of running back under the icon. */
.tt-form-helper--icon {
    display: flex;
    align-items: start;
    gap: var(--space-3xs);
    margin-block-start: var(--space-2xs);
}

/* PLAN OVERRIDES — a day clocked from a production plan time. Each field the plan
   gives a value for has a button in its input group that puts it back, naming it on
   hover; one the day differs on is marked in the accent colour. The :not() keeps this above
   the base input rule, which reaches (0,2,1) through its :is() list. */
/* No box of its own, so the heading and grids stay the .tt-form flex row's own
   items and keep their full width. */
.tt-overrides-part {
    display: contents;
}

.tt-plan-source {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3xs) var(--space-2xs);
    width: 100%;
    margin: 0 0 var(--space-2xs);
    font-size: 0.875rem;
    color: var(--form-label-color);
}

.tt-plan-source .tt-icon {
    margin: 0;
}

.tt-plan-differs-count {
    color: var(--accent-color);
    font-weight: 600;
}

.tt-plan-differs-count::before {
    content: "·";
    margin-inline-end: var(--space-2xs);
    color: var(--form-label-color);
    font-weight: normal;
}

.tt-form .tt-form-row--differs :is(input, select, textarea):not([type="hidden"]) {
    border-color: var(--accent-color);
    box-shadow: inset var(--border-thick) 0 0 var(--accent-color);
}

/* The tooltip's wrapper around the plan button: just the button's size, and a
   stretch so the button stays the field's height. */
.tt-input-group > .tt-plan-use {
    display: flex;
    flex: 0 0 auto;
}

/* The group's one-line seam and hover edge (form-widgets.css) reach only its own
   children, so they are given again to the wrapped button. */
.tt-input-group > .tt-plan-use > .tt-btn {
    border-left: 0;
}

.tt-input-group > .tt-plan-use > .tt-btn-secondary:hover:not(:disabled) {
    box-shadow: calc(-1 * var(--border-thin)) 0 0 var(--primary-color);
}
