// 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 {
    height: 15px;
    width: 15px;
}
// Used in checkbox and radio buttons
label.form-check-label {
    cursor: pointer;
    font-weight: normal;
}
.form-group label.form-check-label.required:after {
    content: '';
}
.form-widget .form-check + .form-check {
    margin-top: 5px;
}

.form-group label.required:after,
.form-group .col-form-label.required:after {
    bottom: 4px;
    color: var(--color-danger);
    content: "\2022"; // \2022 = &bull; (bullet)
    filter: opacity(75%);
    position: relative;
    right: -2px;
    z-index: var(--zindex-700);
}

// 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 {
    border: 1px solid var(--form-input-border-color);
    box-shadow: var(--form-input-shadow);
    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-check-input {
    border: 1px solid var(--gray-400);
    box-shadow: 0 1px 2px 0 var(--gray-50);
}
.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: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 5 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;
}

.nullable-control label,
fieldset .form-group .nullable-control label {
    cursor: pointer;
    margin-top: 5px;
}

// 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 28px 0 0;
    padding: 4px 0px 8px;
}

.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;
    box-shadow: inset 0px -2px 0 0px var(--link-color);
    color: var(--link-color);
    transition: box-shadow .3s ease-in-out;
}

.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(--gray-800);
            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(--gray-800);
}

.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: 0 0 0 1px rgba(43, 45, 80, 0), 0 0 0 1px rgba(183, 6, 32, .2), 0 0 0 2px rgba(183, 6, 32, .25), 0 1px 1px rgba(0, 0, 0, .08);
}

.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-weight: 500;
    padding-top: 6px;
}
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(--gray-100);
    border: 1px solid var(--gray-300);
    box-shadow: 0 1px 2px 0 var(--gray-50);
    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 {
        border-color: transparent transparent transparent var(--button-border-color) !important;
        box-shadow: none !important;
        border-radius: 0;
        color: var(--text-color);
        font-size: 17px;
        height: 30px;
        line-height: 30px;
        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(--white);
        border-radius: var(--border-radius);
        border: 0;
        box-shadow: 0 0 0 1px rgba(43, 45, 80, .16), 0 0 0 1px rgba(6, 122, 184, 0), 0 0 0 2px rgba(6, 122, 184, 0), 0 1px 1px rgba(0, 0, 0, .08);
        color: var(--text-color-dark);
        height: 30px;
        left: 0;
        margin: 0 !important;
        overflow: hidden;
        padding: 3px 40px 3px 7px;
        position: absolute;
        text-align: left !important;
        text-overflow: ellipsis;
        top: 0;
        white-space: nowrap;
        width: 100%;
    }
    .custom-file-label::after {
        display: none;
    }

    .input-group-text {
        background-color: white;
        border: none;
        box-shadow: none;
        color: var(--text-muted);
        height: 30px;
        padding: 7px 0 7px 8px;
        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;
}
