/* =============================================================
   Forms and interactive controls — shared standard.

   Control height, radius, border colour and focus treatment were
   declared per page (32 / 34 / 36 / 38 / 40px heights, 8 / 10 / 11 /
   12px radii, several different focus shadows). This file sets one
   standard through the tokens so inputs, selects, textareas and the
   controls beside them line up on every form.
   ============================================================= */

/* ---------- Text inputs, selects, textareas ---------- */
.form-control,
.form-select {
    min-height: var(--control-height);
    padding: var(--space-2) var(--control-padding-x);
    font-size: var(--fs-md);
    line-height: var(--lh-normal);
    color: var(--color-text);
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

/* Hover is deliberately neutral; validation and focus keep their own colours. */
@media (hover: hover) {
    :is(.form-control, .form-select):hover:not(:focus):not(:disabled):not([readonly]):not(.is-invalid):not(.is-valid) {
        border-color: var(--border-color-strong);
    }
}
@media (prefers-reduced-motion: reduce) {
    .form-control, .form-select { transition: none; }
}

textarea.form-control {
    min-height: calc(var(--control-height) * 2);
    line-height: var(--lh-relaxed);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-control:disabled,
.form-select:disabled,
.form-control[readonly] {
    background-color: var(--surface-muted);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Select needs room for its own chevron so the value never sits
   underneath it — this was patched per page before. */
.form-select {
    padding-right: 2.5rem;
}

/* Small variant, used by table toolbars and pagination. */
.form-control-sm,
.form-select-sm {
    min-height: var(--control-height-sm);
    padding: var(--space-1) var(--space-2);
    font-size: var(--fs-sm);
    border-radius: var(--radius-sm);
}

/* ---------- File inputs ----------
   The browser's grey "Choose File" button ignored the theme (and stayed
   light in dark mode). Every native file input gets the theme's control
   frame and a tinted primary button; the chosen file name stays the
   browser's own text, so behaviour and accessibility are unchanged.
   Inputs hidden behind a drop zone (.visually-hidden) are untouched. */
input[type="file"]:not(.visually-hidden):not([hidden]) {
    max-width: 100%;
    font-size: var(--fs-md);
    color: var(--text-muted);
    cursor: pointer;
}

input[type="file"].form-control {
    padding: var(--space-1);
    line-height: calc(var(--control-height) - var(--space-2) - 2px);
    background-color: var(--surface);
}

input[type="file"]::file-selector-button {
    margin: 0 var(--space-3) 0 0;
    padding: 0 var(--space-3);
    height: calc(var(--control-height) - var(--space-2) - 2px);
    font: inherit;
    font-weight: var(--fw-semibold);
    color: var(--app-primary-text-on-tint, var(--color-primary));
    background: var(--app-primary-subtle, #eff6ff);
    border: 1px solid transparent;
    border-radius: calc(var(--radius-sm) - 2px);
    cursor: pointer;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

/* Bootstrap's own .form-control[type=file] button rules are more specific; match them. */
.form-control[type="file"]::file-selector-button {
    margin: 0 var(--space-3) 0 0;
    padding: 0 var(--space-3);
    color: var(--app-primary-text-on-tint, var(--color-primary));
    background-color: var(--app-primary-subtle, #eff6ff);
    border: 1px solid transparent;
    border-radius: calc(var(--radius-sm) - 2px);
}

@media (hover: hover) {
    input[type="file"]:not(:disabled):hover::file-selector-button,
    .form-control[type="file"]:not(:disabled):hover::file-selector-button {
        color: var(--app-on-primary, #fff);
        background-color: var(--color-primary);
    }
}

input[type="file"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

input[type="file"]:disabled::file-selector-button {
    color: var(--text-muted);
    background: var(--surface-muted);
    cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
    input[type="file"]::file-selector-button { transition: none; }
}

/* ---------- Labels, helper text, validation ---------- */
.form-label {
    display: block;
    margin-bottom: var(--space-1);
    font-size: var(--fs-md);
    font-weight: var(--fw-medium);
    color: var(--color-text);
}

.form-text,
.fg-help-text {
    margin-top: var(--space-1);
    font-size: var(--fs-sm);
    color: var(--text-muted);
}

/* Required marker: one treatment everywhere, and not colour-only
   (the asterisk carries the meaning for screen readers too). */
.form-label .fg-required,
.fg-required {
    color: var(--color-danger);
    margin-left: 2px;
}

.invalid-feedback,
.fg-error-text {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--fs-sm);
    color: var(--color-danger);
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--color-danger);
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .15);
}

/* ---------- Checkboxes, radios, switches ---------- */
.form-check {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: var(--control-height-sm);
    margin-bottom: 0;
    padding-left: 0;
}

.form-check .form-check-input {
    float: none;
    margin: 0;
    flex-shrink: 0;
}

.form-check-input {
    width: var(--icon-size-sm);
    height: var(--icon-size-sm);
    border-color: var(--border-color-strong);
    cursor: pointer;
}

.form-check-input:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.form-check-input:focus-visible {
    box-shadow: var(--focus-ring);
    outline: none;
}

.form-check-input:disabled,
.form-check-input:disabled ~ .form-check-label {
    opacity: .55;
    cursor: not-allowed;
}

.form-check-label {
    font-size: var(--fs-md);
    color: var(--color-text);
    cursor: pointer;
    margin: 0;
}

/* Switch keeps a wider track but the same vertical rhythm. */
.form-switch .form-check-input {
    width: 2.25rem;
    border-radius: var(--radius-pill);
}

/* ---------- Form layout ----------
   Consistent vertical rhythm between fields and between a field and
   its label, so forms on different pages align. */
.fg-form-group,
.form-group {
    margin-bottom: var(--space-4);
}

.fg-form-row {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fg-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    margin-top: var(--space-5);
}

/* ---------- Input groups / search fields ---------- */
.input-group > .form-control,
.input-group > .form-select {
    min-height: var(--control-height);
}

.fg-search {
    position: relative;
}

.fg-search > .form-control {
    padding-left: calc(var(--control-padding-x) + var(--icon-size-sm) + var(--space-2));
}

.fg-search > i,
.fg-search > svg {
    position: absolute;
    left: var(--control-padding-x);
    top: 50%;
    transform: translateY(-50%);
    width: var(--icon-size-sm);
    height: var(--icon-size-sm);
    color: var(--text-muted);
    pointer-events: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 767.98px) {
    .fg-form-row {
        grid-template-columns: 1fr;
    }

    .fg-form-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }
}
