/*
 * LDG System-Wide Form Label and Placeholder Fix v25
 *
 * Additive form-presentation layer for public pages and every dashboard role.
 * It does not change submitted values, field names, validation, or PHP logic.
 */

:root {
    --ldg-field-bg: #ffffff;
    --ldg-field-text: #000000;
    --ldg-field-label: #14213d;
    --ldg-field-placeholder: #707988;
    --ldg-field-border: rgba(20, 33, 61, 0.26);
    --ldg-field-focus: #fca311;
    --ldg-field-danger: #dc3545;
    --ldg-field-radius: 12px;
    --ldg-field-height: 48px;
}

/* ---------------------------------------------------------------
   Shared control behavior
   --------------------------------------------------------------- */

input:not([type="hidden"]),
select,
textarea,
.form-control,
.form-select {
    min-width: 0;
    max-width: 100%;
}

input:not([type="hidden"])::placeholder,
textarea::placeholder,
.form-control::placeholder {
    color: var(--ldg-field-placeholder) !important;
    font-weight: 400 !important;
    opacity: 1 !important;
    text-overflow: ellipsis;
}

input:not([type="hidden"]):focus::placeholder,
textarea:focus::placeholder,
.form-control:focus::placeholder {
    opacity: 0.62 !important;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-text-fill-color: var(--ldg-field-text) !important;
    caret-color: var(--ldg-field-text);
    transition: background-color 9999s ease-out 0s;
}

/* ---------------------------------------------------------------
   Ordinary fields: label stays above the control
   --------------------------------------------------------------- */

.ldg-standard-field {
    position: relative !important;
    display: block;
    min-width: 0;
}

.ldg-standard-field > label:not(.form-check-label),
.ldg-standard-field > .form-label,
.ldg-standard-field > .control-label,
.ldg-standard-field > .field-label,
.ldg-standard-field > legend {
    position: static !important;
    inset: auto !important;
    z-index: auto !important;

    display: block !important;
    width: auto !important;
    max-width: 100%;

    margin: 0 0 0.42rem !important;
    padding: 0 !important;

    color: var(--ldg-field-label) !important;
    background: transparent !important;

    font-size: 0.84rem !important;
    font-weight: 650 !important;
    line-height: 1.35 !important;
    letter-spacing: -0.005em !important;

    opacity: 1 !important;
    pointer-events: auto !important;

    transform: none !important;
    translate: none !important;
    scale: none !important;

    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
}

.ldg-standard-field > input:not([type="hidden"]),
.ldg-standard-field > select,
.ldg-standard-field > textarea,
.ldg-standard-field > .form-control,
.ldg-standard-field > .form-select,
.ldg-standard-field > .input-group {
    position: relative !important;
    z-index: 1;
    width: 100%;
    margin-top: 0 !important;
}

.ldg-standard-field > .input-group {
    display: flex;
}

.ldg-standard-field .form-text,
.ldg-standard-field .invalid-feedback,
.ldg-standard-field .valid-feedback,
.ldg-standard-field .help-block,
.ldg-standard-field .field-help {
    display: block;
    margin-top: 0.38rem;
    line-height: 1.42;
}

/*
 * A few legacy templates place the label and control inside an extra wrapper.
 * JavaScript marks the exact pair with these classes.
 */
.ldg-standard-label {
    position: static !important;
    inset: auto !important;

    display: block !important;

    margin: 0 0 0.42rem !important;
    padding: 0 !important;

    color: var(--ldg-field-label) !important;
    background: transparent !important;

    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
}

.ldg-standard-control {
    position: relative !important;
    z-index: 1;
}

/* ---------------------------------------------------------------
   Bootstrap and custom floating labels
   --------------------------------------------------------------- */

.form-floating,
.ldg-floating-field {
    position: relative !important;
    display: block;
    min-width: 0;
}

/*
 * Reserve a dedicated upper line for the label and a lower line for the value.
 * The label can never share the same vertical space as entered text.
 */
.form-floating > .form-control,
.form-floating > .form-select,
.form-floating > input:not([type="hidden"]),
.form-floating > select,
.form-floating > textarea,
.ldg-floating-field > .form-control,
.ldg-floating-field > .form-select,
.ldg-floating-field > input:not([type="hidden"]),
.ldg-floating-field > select,
.ldg-floating-field > textarea {
    min-height: 58px !important;
    height: auto;

    padding:
        1.55rem
        0.88rem
        0.42rem !important;

    color: var(--ldg-field-text) !important;
    line-height: 1.35 !important;

    border:
        1px solid
        var(--ldg-field-border) !important;
    border-radius:
        var(--ldg-field-radius) !important;
    background-color:
        var(--ldg-field-bg) !important;

    box-shadow: none;
}

/*
 * The real placeholder is hidden while the floating label occupies the field.
 * It becomes visible only while the empty field has focus.
 */
.form-floating > .form-control::placeholder,
.form-floating > input::placeholder,
.form-floating > textarea::placeholder,
.ldg-floating-field > .form-control::placeholder,
.ldg-floating-field > input::placeholder,
.ldg-floating-field > textarea::placeholder {
    color: transparent !important;
    opacity: 0 !important;
}

.form-floating > .form-control:focus::placeholder,
.form-floating > input:focus::placeholder,
.form-floating > textarea:focus::placeholder,
.ldg-floating-field > .form-control:focus::placeholder,
.ldg-floating-field > input:focus::placeholder,
.ldg-floating-field > textarea:focus::placeholder {
    color: var(--ldg-field-placeholder) !important;
    opacity: 0.72 !important;
}

.form-floating > label,
.ldg-floating-field > label {
    position: absolute !important;
    inset:
        0
        auto
        auto
        0 !important;
    z-index: 3 !important;

    display: block !important;
    width: calc(100% - 1.1rem) !important;
    height: auto !important;

    margin: 0 !important;
    padding:
        0.88rem
        0.88rem
        0 !important;

    color: var(--ldg-field-placeholder) !important;
    background: transparent !important;

    font-size: 0.92rem !important;
    font-weight: 500 !important;
    line-height: 1.25 !important;

    opacity: 1 !important;
    pointer-events: none !important;

    transform-origin: 0 0 !important;
    transform:
        translateY(0)
        scale(1) !important;

    transition:
        transform 160ms ease,
        color 160ms ease,
        font-weight 160ms ease,
        padding 160ms ease !important;

    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/*
 * Focused, filled, selected, autofilled, date/time and programmatically marked
 * fields keep the label in the reserved upper line.
 */
.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label,
.form-floating > input:focus ~ label,
.form-floating > input:not(:placeholder-shown) ~ label,
.form-floating > textarea:focus ~ label,
.form-floating > textarea:not(:placeholder-shown) ~ label,
.form-floating > select ~ label,
.form-floating > .form-select ~ label,
.form-floating > input:-webkit-autofill ~ label,
.form-floating.ldg-has-value > label,
.form-floating.ldg-force-float > label,
.ldg-floating-field > .form-control:focus ~ label,
.ldg-floating-field > .form-control:not(:placeholder-shown) ~ label,
.ldg-floating-field > input:focus ~ label,
.ldg-floating-field > input:not(:placeholder-shown) ~ label,
.ldg-floating-field > textarea:focus ~ label,
.ldg-floating-field > textarea:not(:placeholder-shown) ~ label,
.ldg-floating-field > select ~ label,
.ldg-floating-field > .form-select ~ label,
.ldg-floating-field > input:-webkit-autofill ~ label,
.ldg-floating-field.ldg-has-value > label,
.ldg-floating-field.ldg-force-float > label {
    padding:
        0.34rem
        0.88rem
        0 !important;

    color: var(--ldg-field-label) !important;
    font-size: 0.78rem !important;
    font-weight: 700 !important;

    transform:
        translateY(0)
        scale(0.92) !important;
}

/* Bootstrap validation icons retain enough right-side space. */
.form-floating > .form-control.is-valid,
.form-floating > .form-control.is-invalid,
.ldg-floating-field > .form-control.is-valid,
.ldg-floating-field > .form-control.is-invalid {
    padding-right: 2.8rem !important;
}

/* Prefix/suffix groups remain above labels and never cover text. */
.form-floating .input-group,
.ldg-floating-field .input-group {
    position: relative;
    z-index: 2;
}

/* ---------------------------------------------------------------
   Focus, validation and disabled states
   --------------------------------------------------------------- */

.form-floating > .form-control:focus,
.form-floating > .form-select:focus,
.ldg-floating-field > .form-control:focus,
.ldg-floating-field > .form-select:focus,
.ldg-standard-field .form-control:focus,
.ldg-standard-field .form-select:focus {
    border-color:
        var(--ldg-field-focus) !important;
    box-shadow:
        0 0 0 0.22rem
        rgba(252, 163, 17, 0.17) !important;
}

.form-floating > .is-invalid,
.ldg-floating-field > .is-invalid,
.ldg-standard-field .is-invalid {
    border-color:
        var(--ldg-field-danger) !important;
}

.form-floating > .form-control:disabled,
.form-floating > .form-select:disabled,
.form-floating > .form-control[readonly],
.ldg-floating-field > .form-control:disabled,
.ldg-floating-field > .form-select:disabled,
.ldg-floating-field > .form-control[readonly] {
    background-color: #f1f3f5 !important;
    opacity: 1;
}

.form-floating > .form-control:disabled ~ label,
.form-floating > .form-select:disabled ~ label,
.ldg-floating-field > .form-control:disabled ~ label,
.ldg-floating-field > .form-select:disabled ~ label {
    color: #6c757d !important;
}

/* Checkbox/radio labels must remain beside their controls. */
.form-check,
.form-switch {
    position: relative;
}

.form-check > label,
.form-switch > label,
.form-check-label {
    position: static !important;
    display: inline-block !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    pointer-events: auto !important;
}

/* ---------------------------------------------------------------
   Dark surfaces
   --------------------------------------------------------------- */

[data-bs-theme="dark"],
.dark-mode,
.theme-dark {
    --ldg-field-bg: #111827;
    --ldg-field-text: #ffffff;
    --ldg-field-label: #fca311;
    --ldg-field-placeholder: #aeb6c3;
    --ldg-field-border: rgba(229, 229, 229, 0.28);
}

[data-bs-theme="dark"] .form-floating > label,
[data-bs-theme="dark"] .ldg-floating-field > label,
.dark-mode .form-floating > label,
.dark-mode .ldg-floating-field > label,
.theme-dark .form-floating > label,
.theme-dark .ldg-floating-field > label {
    color: var(--ldg-field-placeholder) !important;
}

/* ---------------------------------------------------------------
   Mobile protection
   --------------------------------------------------------------- */

@media (max-width: 767.98px) {
    input:not([type="hidden"]),
    select,
    textarea,
    .form-control,
    .form-select {
        font-size: 16px !important;
    }

    .form-floating > label,
    .ldg-floating-field > label {
        font-size: 0.88rem !important;
    }

    .form-floating > .form-control,
    .form-floating > .form-select,
    .ldg-floating-field > .form-control,
    .ldg-floating-field > .form-select {
        min-height: 60px !important;
    }
}

@media print {
    .form-floating > label,
    .ldg-floating-field > label {
        color: #000000 !important;
    }
}
