// Forms
// ----------------------------------------------------------------------------

input[disabled] {
    cursor: not-allowed;
}

.form-inline {
    align-items: center;
    display: flex;
    flex-flow: row wrap;
}

// Base form groups
.form-group {
    padding: 12px 0;
}

.form-group label,
.form-group legend.col-form-label {
    color: var(--form-label-color);
    font-size: var(--font-size-base);
    font-weight: 500;
    margin: 0;
    padding: 0 0 8px 0;
}

.form-check .form-check-input {
    border-color: var(--form-type-check-input-border-color);
    height: 15px;
    width: 15px;
}
.form-check:not(.form-switch) .form-check-input:not(:checked) {
    background-color: unset;
}
// Used in checkbox and radio buttons
label.form-check-label {
    cursor: pointer;
    font-weight: normal;
}
.form-group label.form-check-label.required:after {
    display: none;
}
.form-widget .form-check + .form-check {
    margin-top: 5px;
}

.form-group label.required:after,
.form-group .col-form-label.required:after {
    background: var(--color-danger);
    border-radius: 50%;
    content: '';
    display: inline-block;
    filter: opacity(75%);
    position: relative;
    right: -2px;
    top: -8px;
    z-index: var(--zindex-700);
    height: 4px;
    width: 4px;
}

// Form widgets (inputs, selects, etc.)
.form-widget {
}

.form-widget .form-help {
    color: var(--form-help-color);
    display: block;
    font-size: var(--font-size-sm);
    margin-top: 5px;
    transition: color 0.5s ease;
}
.form-widget:focus-within .form-help {
    color: var(--form-help-active-color);
}

.form-widget input.form-control,
.form-widget textarea.form-control,
.form-widget .form-select {
    background-color: var(--form-control-bg);
    background-repeat: no-repeat; // see https://github.com/EasyCorp/EasyAdminBundle/issues/5197
    border: 1px solid var(--form-input-border-color);
    box-shadow: var(--form-input-shadow);
    color: var(--form-input-text-color);
    height: 30px;
    padding: 3px 7px 4px;
    white-space: nowrap;
    word-break: keep-all;
    transition: box-shadow .08s ease-in, color .08s ease-in;
}
.form-widget input.form-control.is-invalid,
.form-widget textarea.form-control.is-invalid,
.form-widget .form-select.is-invalid,
.form-widget input.form-control.is-invalid:focus,
.form-widget textarea.form-control.is-invalid:focus,
.form-widget .form-select.is-invalid:focus {
    background-image: none;
    border: 1px solid var(--form-input-error-border-color);
    box-shadow: var(--form-input-error-shadow);
}
.form-widget input.form-check-input.is-invalid {
    border: 1px solid var(--form-input-error-border-color);
    box-shadow: var(--form-input-error-shadow);
}

.form-widget .form-control:disabled,
.form-widget .form-control[readonly],
.form-widget .form-select:disabled,
.form-widget .form-select[readonly] {
    background-color: var(--form-control-disabled-bg);
    color: var(--form-control-disabled-color);
}
body.ea-dark-scheme .form-widget .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23adb5bd' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

.form-widget .form-select[multiple] {
    height: auto;
    background-image: none;
    padding: 0;
}
.form-widget input.form-check-input {
    border: 1px solid var(--form-type-check-input-border-color);
    box-shadow: var(--form-type-check-input-box-shadow);
}
.form-widget input.form-control:focus,
.form-widget textarea.form-control:focus,
.form-widget .form-select:focus,
.form-widget .custom-file-input:focus ~ .custom-file-label,
.form-widget input.form-check-input:focus {
    border-color: var(--form-input-hover-border-color);
    box-shadow: var(--form-input-hover-shadow);
    outline: 0;
}
.form-check-input:checked {
    background-color: var(--form-type-check-input-checked-bg);
}
.form-check-input:focus {
    box-shadow: var(--form-input-hover-shadow);
}

.form-widget .form-control + .input-group-append {
    color: var(--gray-600);
    height: 30px;
}
.form-widget .form-control + .input-group-append i {
    color: var(--gray-600);
}

.form-widget input.form-control[data-ea-align=right] {
    text-align: right;
}
.form-widget input.form-control.is-invalid[data-ea-align=right] {
    padding-right: 30px;
}

.form-widget textarea.form-control {
    height: auto;
    line-height: 1.6;
    white-space: pre-wrap;
}

.form-widget .form-select {
    background-position: right 5px center;
    padding: 3px 28px 4px 7px;
}
.ts-dropdown.form-select {
    height: auto;
}

// Checkbox widgets
.form-widget .form-check {
    margin: 0;
    padding: 0;
}
label.form-check-label {
    margin: 0;
    padding: 0 0 0 5px;
}
.form-check .form-check-input {
    float: none;
    margin-left: 0;
    margin-top: 2px;
}
.form-check-inline + .form-check-inline {
    margin-left: 15px;
}

// in Bootstrap custom file widgets, the label is used to simulate the file input
.field-file .custom-file, .field-file .custom-file-input {
    height: 30px;
}
.field-file .custom-file label.custom-file-label {
    height: 30px;
    margin: 0;
    max-width: 350px;
    overflow: hidden;
    padding: 3px 7px 5px;
    text-align: left;
}
.field-file .custom-file label.custom-file-label:after {
    color: var(--text-color);
    content: "\f07c";
    display: inline-block;
    font-family: "Font Awesome 6 Free";
    font-size: 17px;
    height: 28px;
    line-height: 28px;
    padding: 0 8px;
    vertical-align: middle;
}

// Date-time widgets
.field-date .form-widget,
.field-time .form-widget,
.field-datetime .form-widget {
    margin: 0;
}

.datetime-widget select,
.datetime-widget .input-group > .form-select {
    min-width: max-content;
    -webkit-appearance: none; // needed for Safari
}
.datetime-widget + .datetime-widget {
    margin-left: 10px;
}

.datetime-widget select + select {
    margin-left: 4px;
}

.datetime-widget-time select {
    margin: 0 0 0 2px;
}
.datetime-widget-time select:first-child {
    margin-left: 0;
}
.datetime-widget-time select:last-child {
    margin-right: 0;
}

// Utilities to create common form fields (long, short, etc.)
.short .form-widget {
    flex: 0 0 20% !important;
}

.long .form-control, .large .form-control {
    max-width: unset !important;
}

.large .input.form-control {
    font-size: 18px !important;
}

.large textarea.form-control {
    height: 500px;
    max-width: unset !important;
}

.code input.form-control, .code textarea.form-control {
    font-family: monospace !important;
}

.field-group .long .form-control, .field-group .large .form-control {
    flex: 0 0 100% !important;
    max-width: unset !important;
}

.field-group .large textarea.form-control {
    flex: 0 0 100% !important;
    height: 500px;
    max-width: unset !important;
}

// Form tabs
.form-tabs .nav-tabs {
    background: transparent;
    border: 0;
    box-shadow: 0 1px 0 var(--form-tabs-border-color);
    margin: 0px 0px 20px;
    padding-left: 0px;
}

.form-tabs .nav-tabs a, .form-tabs .nav-tabs a:hover {
    border: 0;
    color: var(--text-color);
    font-size: var(--font-size-base);
    font-weight: 500;
    margin: 0;
    padding: 4px 14px 8px;
}
.form-tabs .nav-tabs .nav-item:first-child a, .form-tabs .nav-tabs .nav-item:first-child a:hover {
     padding-left: 0;
 }

.form-tabs .nav-tabs .fa {
    color: var(--text-muted);
    font-size: var(--font-size-lg);
    margin-right: 4px;
}

.form-tabs .nav-tabs .nav-link.active {
    background: transparent;
    color: var(--link-color);
    position: relative;
}
.form-tabs .nav-tabs .nav-link.active:before {
    content: '';
    width: 100%;
    height: 2px;
    background: var(--body-bg);
    position: absolute;
    bottom: -1px;
    left: 0;
}
.form-tabs .nav-tabs .nav-link.active:after {
    content: '';
    width: calc(100% - 2 * var(--form-tabs-gutter-x));
    height: 2px;
    background: var(--link-color);
    position: absolute;
    bottom: -1px;
    left: var(--form-tabs-gutter-x);
}
.form-tabs .nav-tabs .nav-item:first-child .nav-link.active:after {
    width: calc(100% - var(--form-tabs-gutter-x));
    left: 0;
}

.form-tabs .nav-tabs .nav-item .badge {
    margin-left: 4px;
    padding: 3px 6px;
}

.form-tabs .tab-help {
    margin-top: -10px;
    margin-bottom: 15px;
}

// Form fieldsets (used for the "from groups" feature)
fieldset {
    background: var(--fieldset-bg);
    border: var(--border-width) var(--border-style) var(--border-color);
    border-radius: var(--border-radius);
    margin: 10px 0;
    padding: 10px 20px 15px;
}

fieldset > legend {
    border: 0;
    font-size: var(--font-size-sm);
    font-weight: 500;
    text-transform: uppercase;
    margin: 0 0 5px -5px;
    padding: 0 5px;
    width: auto;
}
fieldset > legend .fa {
    color: var(--text-muted);
    font-size: var(--font-size-lg);
    margin-right: 4px;
}

fieldset .form-section {
    padding-left: 0;
    padding-right: 0;
}

fieldset .form-group {
    padding: 10px 0;
}

fieldset .form-group label,
fieldset .form-group legend.col-form-label {
    flex: 100% 0 0;
    margin: 0 0 4px 0;
    text-align: left;
}

fieldset .form-group .form-widget,
fieldset .field-checkbox .form-widget {
    flex: 0 0 100%;
    padding-left: 0;
    padding-right: 0;
}

fieldset .field-checkbox .form-widget,
fieldset .form-group.field-collection-action {
    margin-left: 0;
}

fieldset .form-group.field-collection-action {
    padding-top: 0;
}

fieldset .field-collection-action .btn {
    margin-left: 0;
}

fieldset .legend-help {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    margin-bottom: 15px;
    margin-top: -5px;
}

// Form sections
.form-panel {
    padding: 0 0 20px;
}

.form-section-empty {
    padding: 25px 10px 25px;
}

.form-panel-header {
    align-items: flex-start;
    box-shadow: 0 1px 0 var(--form-panel-header-border-color);
    display: flex;
    flex-wrap: nowrap;
    padding: 15px 0 10px;
    position: relative;

    .form-panel-collapse-marker {
        color: var(--form-panel-collapse-marker-color);
        margin: 0 10px 0 2px;
        transform: rotate(90deg);
        transition: transform .2s ease-in-out;
    }

    .form-panel-title {
        flex: 1;

        a {
            color: var(--form-panel-header-color);
            font-size: 20px;
            font-weight: bold;

            &.not-collapsible { cursor: default; }
            &.collapsed {
                .form-panel-collapse-marker {
                    transform: rotate(0deg);
                }
            }

            &::after {
                content: '';
                position: absolute;
                width: 100%;
                height: 100%;
                top: 0;
                left: 0;
            }
        }

        .form-panel-icon {
            color: var(--form-panel-icon-color);
            margin-right: 5px;
        }

        .form-panel-help {
            color: var(--form-panel-help-color);
        }
    }
}

.form-panel-body {
    padding-top: 5px;
}

// Form actions ("Save changes", "Delete", etc.)
.form-actions {
    display: flex;
    justify-content: flex-end;
    padding: 0;
}
.form-actions .btn {
    margin-left: 10px;
}

// Form errors
.has-error .form-help, .has-error .control-label, .has-error .radio,
.has-error .checkbox, .has-error .radio-inline, .has-error .checkbox-inline,
.has-error.radio label, .has-error.checkbox label, .has-error.radio-inline label,
.has-error.checkbox-inline label {
    color: var(--form-help-error-color);
}

.has-error .form-widget input.form-control,
.has-error .form-widget textarea.form-control,
.has-error .form-widget .form-select,
.has-error .ea-fileupload .input-group,
.has-error .btn.input-file-container,
.has-error .CodeMirror,
.has-error .ea-text-editor-wrapper {
    box-shadow: var(--form-input-error-shadow);
}

.has-error .ea-fileupload .input-group {
    border-radius: var(--border-radius);
}

.global-invalid-feedback {
    background: var(--red-100);
    border-radius: var(--border-radius);
    color: var(--color-danger);
    font-size:  14px;
    margin:  5px 0;
    padding: 6px 12px;
}
form .invalid-feedback {
    color: var(--color-danger);
    font-size: 1em;
    font-weight: 500;
    padding-top: 6px;
}
.form-check-input.is-invalid ~ .form-check-label,
.was-validated .form-check-input:not([type="checkbox"]):invalid ~ .form-check-label {
    color: inherit;
}

form .invalid-feedback .badge-danger {
    font-size: 0.6875rem;
    margin-right: 2px;
    padding: 3px 4px;
}
form .invalid-feedback > .d-block + .d-block {
    margin-top: 5px;
}

// Form group inputs
.input-group-text {
    background-color: var(--form-input-group-text-bg);
    border: 1px solid var(--form-input-group-text-border-color);
    box-shadow: var(--form-input-box-shadow);
    color: var(--form-input-text-color);
    height: 30px;
    padding: 3px 10px 5px;
}
.input-group button,
.input-group button:hover,
.input-group button:active,
.input-group button:focus {
    height: 28px;
    margin-top: 1px;
}

.input-group-append {
    margin-left: 0;
}
.input-group-prepend {
    margin-right: 0;
}

//fileupload widgets
.ea-fileupload {
    .custom-file {
        height: 30px;
    }
    .input-group {
        flex-wrap: nowrap;
    }
    .input-group .btn,
    .input-group .btn:hover {
        background: var(--form-input-group-text-bg);
        box-shadow: none !important;
        border-radius: 0;
        color: var(--text-color);
        font-size: 17px;
        height: 28px;
        line-height: 28px;
        margin: 0;
        padding: 0 8px;
        vertical-align: middle;

        &:first-child {
            margin-left: 5px;
        }
        &:last-child {
            border-top-right-radius: var(--border-radius);
            border-bottom-right-radius: var(--border-radius);
        }
    }

    .custom-file-input {
        cursor: pointer;
        height: calc(1.5em + .75rem + 2px);
        margin: 0;
        overflow: hidden;
        opacity: 0;
        position: relative;
        width: 100%;
        z-index: 2;
    }

    .custom-file-label {
        background: var(--form-control-bg);
        border-radius: var(--border-radius);
        border: 1px solid var(--form-input-border-color);
        box-shadow: var(--form-input-shadow);
        color: var(--form-input-text-color);
        height: 30px;
        left: 0;
        margin: 0 !important;
        overflow: hidden;
        padding: 3px 40px 3px 7px !important;
        position: absolute;
        text-align: left !important;
        text-overflow: ellipsis;
        top: 0;
        white-space: nowrap;
        width: 100% !important;
    }
    .custom-file-label::after {
        display: none;
    }

    .input-group-text {
        background: var(--form-input-group-text-bg);
        border: 1px solid var(--form-input-border-color);
        box-shadow: none;
        color: var(--text-muted);
        height: 30px;
        padding: 7px 0 7px 7px;
        position: absolute;
        right: 0;
        z-index: 3;
    }

    .fileupload-list {
        height: auto;
        margin-top: 7px;
        padding: 0;

        .fileupload-table {
            width: 100%;
        }
        .fileupload-table td {
            padding: 3px 7px;
            border-radius: 3px;
        }
        .fileupload-table td:first-child {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            max-width: 300px;
        }
        .fileupload-table tr:nth-child(odd) td {
            background-color: #f5f7ff;
        }
        .fileupload-table td.file-size {
            color: #4e566d;
        }
    }
}

// Image/file vich uploads
.ea-vich-image img {
    box-shadow: 0 0 0 4px var(--white), 0px 0px 4px 3px var(--gray-600);
    margin: 6px 4px 12px;
    max-height: 300px;
    max-width: 100%;
}

.ea-vich-file-name {
    display: block;
    margin: 4px 0 8px;
}

.ea-vich-file-name .fa {
    font-size: 18px;
}

// this element should use 'display: flex', but that doesn't work with
// the CSS trick used to customize the <input type="file" /> fields.

.ea-vich-image-actions > div,
.ea-vich-file-actions > div {
    float: left;
    margin-right: 4px;
}

.ea-vich-image-actions:after,
.ea-vich-file-actions:after {
    clear: left;
    content: "";
    display: block;
}

.ea-vich-image-actions .field-checkbox,
.ea-vich-file-actions .field-checkbox {
    padding-top: 4px;
}

.ea-vich-image-actions .form-widget {
    flex-basis: 100%;
}

// This CSS trick allows to customize the <input type="file" /> field entirely
// as explained in https://gist.github.com/barneycarroll/5244258
.input-file-container {
    overflow: hidden;
    position: relative;
}

.input-file-container [type=file] {
    cursor: inherit;
    display: block;
    font-size: 999px;
    filter: opacity(0);
    min-height: 100%;
    min-width: 100%;
    opacity: 0;
    position: absolute;
    right: 0;
    text-align: right;
    top: 0;
}

// Fix "Browse" button for regular file inputs
.form-control {
    &::file-selector-button, &::-webkit-file-upload-button {
        color: var(--button-secondary-color);
        background-color: var(--button-secondary-bg);
        box-shadow: var(--button-shadow);
    }

    &:hover:not(:disabled):not([readonly]) {
        &::file-selector-button, &::-webkit-file-upload-button {
            background-color: var(--button-secondary-bg);
            box-shadow: var(--button-hover-shadow);
        }
    }
}
