/* Forms: create/update pages (components/_form.html) and modal forms. */

/* The edge of every control and its focus (tokens.css: --ec-input-border,
   --ec-focus-color). Tabler draws them with the divider grey and a 25% ring,
   both under the 3:1 of WCAG. The invalid and valid states keep their own
   colours: their selectors (.is-invalid) weigh more than these. */
.form-control,
.form-select,
.form-check-input,
.input-group-flat .input-group-text,
.ts-wrapper:not(.form-control, .form-select) .ts-control {
    border-color: var(--ec-input-border);
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus-visible {
    --tblr-focus-ring-color: var(--ec-focus-color);
    border-color: var(--ec-focus-color);
}

/* A field with an error keeps its red, also in the ring: the pure red
   (Tabler draws it at 25%, 2:1 on white). */
.form-control.is-invalid:focus,
.form-select.is-invalid:focus,
.form-check-input.is-invalid:focus-visible {
    outline-color: var(--tblr-form-invalid-border-color);
}

/* Tom Select: the focus is on its wrapper (the select's classes travel to it). */
.ts-wrapper.form-select.focus,
.ts-wrapper.form-control.focus {
    border-color: var(--ec-focus-color);
    outline: var(--tblr-focus-ring-width) solid var(--ec-focus-color);
    outline-offset: -1px;
}

.ts-wrapper.is-invalid.focus {
    border-color: var(--tblr-form-invalid-border-color);
    outline-color: var(--tblr-form-invalid-border-color);
}

/* A field with an icon or a text glued to it: the group shows the focus. */
.input-group-flat:focus-within {
    --tblr-focus-ring-color: var(--ec-focus-color);
}

.input-group-flat:focus-within .form-control,
.input-group-flat:focus-within .input-group-text {
    border-color: var(--ec-focus-color) !important;
}

/* The error text of a field: Tabler's red as text is 4.2:1 on white, under
   the 4.5:1 of AA. The readable red of the tokens; the border stays red. */
.invalid-feedback {
    color: var(--ec-text-danger);
}

/* Boolean field as a boxed switch (components/_switch_field.html). */
.form-switch-field {
    padding: .75rem 1rem;
    border: var(--tblr-border-width) solid var(--tblr-border-color);
    border-radius: var(--tblr-border-radius);
    background: var(--tblr-bg-surface-secondary);
}

/* The whole box is the label: clicking the text toggles the switch. */
.form-switch-field .form-check {
    cursor: pointer;
}

/* Switches at the end of a section card, after its fields; side by side when they fit. */
.form-switches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
    gap: .75rem;
}

/* A single switch that owns its whole half of the row (the history form). */
.form-switches--single {
    grid-template-columns: minmax(0, 1fr);
}

/* Footer of the form: stays reachable at the end of long forms. */
.form-actions {
    padding-bottom: 1rem;
}

/* Tom Select multi-select: remove button of each chosen item (form.js). */
.ts-item-remove {
    margin-left: .25rem;
    padding: 0 .125rem;
    border: 0;
    background: none;
    color: inherit;
    opacity: .7;
    line-height: 1;
    cursor: pointer;
}

.ts-item-remove:hover,
.ts-item-remove:focus-visible {
    opacity: 1;
}

/* Reveal button of a password field (components/_password_field.html). */
.password-toggle > .ti {
    line-height: 1;
}

/* The password rules column: the validators' help text, a plain <ul> that Django
   builds (accounts/password_change_page.html), spaced out as a list to read. */
.password-rules ul {
    padding-inline-start: 1.25rem;
    margin-bottom: 0;
}

.password-rules li + li {
    margin-top: .25rem;
}

/* Segmented choice (patients/_patient_fields.html, the scope of an agenda block):
   one row from sm up, stacked on phones, where the options don't fit side by side. */

/* The chosen option uses the link blue, which Tabler lightens in the dark theme:
   its own primary on the dark tint was 2.8:1, under the 4.5:1 of AA. */
.btn-group-stack-sm > .btn-check:checked + .btn {
    color: var(--tblr-link-color);
    border-color: var(--tblr-link-color);
}

@media (max-width: 575.98px) {
    .btn-group-stack-sm {
        flex-direction: column;
    }

    /* Stacked, each option is a thumb-sized row (44px). */
    .btn-group-stack-sm > .btn {
        width: 100%;
        min-height: 2.75rem;
        margin-left: 0 !important;
        border-radius: 0 !important;
    }

    .btn-group-stack-sm > .btn ~ .btn {
        margin-top: calc(-1 * var(--tblr-border-width));
    }

    .btn-group-stack-sm > .btn:first-of-type {
        border-top-left-radius: var(--tblr-border-radius) !important;
        border-top-right-radius: var(--tblr-border-radius) !important;
    }

    .btn-group-stack-sm > .btn:last-child {
        border-bottom-left-radius: var(--tblr-border-radius) !important;
        border-bottom-right-radius: var(--tblr-border-radius) !important;
    }
}

/* Collapsible cards (optional address, permissions): the whole header folds the card. */
.card-collapse__toggle {
    display: flex;
    align-items: center;
    gap: .5rem;
    width: 100%;
    text-align: start;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

.card-collapse__toggle.collapsed {
    border-bottom: 0;
}

.card-collapse__toggle:focus-visible {
    outline: 2px solid var(--tblr-primary);
    outline-offset: -2px;
}

.card-collapse__chevron {
    color: var(--tblr-secondary);
    transition: transform .15s ease;
}

.card-collapse__toggle:not(.collapsed) .card-collapse__chevron {
    transform: rotate(180deg);
}

@media (prefers-reduced-motion: reduce) {
    .card-collapse__chevron {
        transition: none;
    }
}

/* The fields of a person that are shown but never edited (the document of
   an account or of a patient, how they found the clinic): they look locked,
   not like a field to fill in (users/_person_card.html,
   patients/_patient_person_fields.html). */
.person-fields .form-control[readonly],
.person-fields .form-select:disabled,
.person-fields .form-control[readonly]:hover,
.person-fields .form-select:disabled:hover {
    background-color: var(--tblr-bg-surface-secondary);
    color: var(--tblr-secondary);
}

.person-fields .form-control[readonly],
.person-fields .form-select:disabled {
    cursor: default;
}


/* Login page: forgot-password link above the password field. */
.login-forgot-link {
    z-index: 11;
}

/* Login page: eye button over the password field. */
.btn-link.password-toggle {
    border: none;
    background: none;
    z-index: 10;
}
