/* ============================================================================
   Forms - inputs, Select2, datepicker, checkboxes, validation
   ============================================================================ */

/* custom.css line 1201 ships `.control-label, label { color: #fff }`
   site-wide. That makes every form label invisible in light mode.
   Override with !important so labels track the active theme. */
body.theme-new .control-label,
body.theme-new label,
body.theme-new .form-group > label {
    color: var(--text-main) !important;
    font-weight: 500;
    margin-bottom: 6px;
}

body.theme-new .form-control {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    color: var(--text-main);
    box-shadow: none;
    transition:
        border-color var(--transition-speed) var(--ease-standard),
        background var(--transition-speed) var(--ease-standard),
        box-shadow var(--transition-speed) var(--ease-standard);
}

body.theme-new .form-control::placeholder {
    color: var(--input-placeholder);
}

body.theme-new .form-control:focus {
    border-color: var(--input-focus);
    outline: none;
    background: var(--input-bg);
    color: var(--text-main);
    box-shadow: 0 0 0 3px var(--primary-focus);
}

body.theme-new .form-control[disabled],
body.theme-new .form-control[readonly],
body.theme-new fieldset[disabled] .form-control {
    background: var(--bg-elevated);
    color: var(--text-muted);
    opacity: 0.7;
}

body.theme-new .form-group {
    margin-bottom: 18px;
}

body.theme-new .help-block,
body.theme-new .form-text {
    color: var(--text-muted);
    font-size: 12px;
}

/* Validation */
body.theme-new .has-error .control-label,
body.theme-new .has-error .help-block {
    color: var(--danger-color);
}

body.theme-new .has-error .form-control,
body.theme-new .form-control.is-invalid {
    border-color: var(--danger-color);
    box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.18);
}

body.theme-new .has-success .form-control {
    border-color: var(--success-color);
}

/* Input group */
body.theme-new .input-group-addon,
body.theme-new .input-group-btn .btn {
    background: var(--bg-elevated);
    border-color: var(--input-border);
    color: var(--text-main);
}

/* Selects (native).
   `appearance: none` removes the OS chrome so the custom-drawn chevron
   below can take over. The flip side is the browser stops vertically
   centering the option text inside its default height — descenders
   ("p", "g", "y") were getting clipped at the bottom border. We
   explicitly set padding / line-height / min-height to make sure the
   text + its descenders always fit. */
body.theme-new select.form-control {
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
        linear-gradient(-45deg, transparent 50%, var(--text-muted) 50%);
    background-position:
        calc(100% - 18px) calc(50% - 2px),
        calc(100% - 12px) calc(50% - 2px);
    background-size: 6px 6px;
    background-repeat: no-repeat;
    appearance: none;
    -webkit-appearance: none;
    height: auto;
    min-height: 36px;
    line-height: 1.5;
    padding: 7px 28px 7px 12px;
}
body.theme-new select.form-control.input-sm {
    min-height: 32px;
    padding: 5px 26px 5px 10px;
    font-size: 12px;
    line-height: 1.5;
}

/* Bootstrap-select (the JS-enhanced selects Perfex uses) */
body.theme-new .bootstrap-select > .btn,
body.theme-new .bootstrap-select.btn-group .dropdown-toggle {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-main);
}

body.theme-new .bootstrap-select > .btn:focus,
body.theme-new .bootstrap-select.btn-group.open .dropdown-toggle {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px var(--primary-focus);
}

body.theme-new .bootstrap-select .dropdown-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elev);
}

body.theme-new .bootstrap-select .dropdown-menu > li > a {
    color: var(--text-main);
    border-radius: var(--radius-sm);
    transition: background var(--transition-speed) var(--ease-standard);
}

body.theme-new .bootstrap-select .dropdown-menu > li > a:hover,
body.theme-new .bootstrap-select .dropdown-menu > li.selected > a {
    background: var(--primary-tint);
    color: var(--text-heading);
}

body.theme-new .bootstrap-select .bs-searchbox .form-control {
    background: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-main);
}

/* Select2 (the other selector library Perfex / Selectize use in places) */
body.theme-new .select2-container--default .select2-selection,
body.theme-new .select2-container--bootstrap .select2-selection {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-main);
    border-radius: var(--radius-sm);
}

body.theme-new .select2-container--default .select2-selection__rendered,
body.theme-new .select2-container--bootstrap .select2-selection__rendered {
    color: var(--text-main);
}

body.theme-new .select2-container--default.select2-container--focus .select2-selection,
body.theme-new .select2-container--default.select2-container--open .select2-selection {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px var(--primary-focus);
}

body.theme-new .select2-dropdown {
    background: var(--bg-card);
    border-color: var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elev);
}

body.theme-new .select2-results__option--highlighted,
body.theme-new .select2-container--default .select2-results__option--highlighted[aria-selected],
body.theme-new .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background: var(--primary-tint);
    color: var(--text-heading);
}

body.theme-new .select2-search--dropdown .select2-search__field {
    background: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text-main);
    border-radius: var(--radius-sm);
}

body.theme-new .select2-selection__choice {
    background: var(--primary-tint) !important;
    border-color: var(--primary-color) !important;
    color: var(--text-heading) !important;
    border-radius: var(--radius-full) !important;
    padding: 2px 10px !important;
}

/* bootstrap-datetimepicker */
body.theme-new .bootstrap-datetimepicker-widget.dropdown-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elev);
    color: var(--text-main);
}

body.theme-new .bootstrap-datetimepicker-widget table td,
body.theme-new .bootstrap-datetimepicker-widget table th {
    color: var(--text-main);
}

body.theme-new .bootstrap-datetimepicker-widget table th {
    color: var(--text-muted);
    font-weight: 600;
}

body.theme-new .bootstrap-datetimepicker-widget table td.day:hover,
body.theme-new .bootstrap-datetimepicker-widget table td.hour:hover,
body.theme-new .bootstrap-datetimepicker-widget table td.minute:hover {
    background: var(--primary-tint);
    color: var(--text-heading);
}

body.theme-new .bootstrap-datetimepicker-widget table td.active,
body.theme-new .bootstrap-datetimepicker-widget table td.active:hover {
    background: var(--primary-color);
    color: var(--bg-body);
    font-weight: 600;
}

body.theme-new .bootstrap-datetimepicker-widget table td.today::before {
    border-bottom-color: var(--primary-color);
}

/* Perfex custom checkboxes */
body.theme-new .checkbox label::before {
    background: var(--input-bg);
    border-color: var(--input-border);
}

body.theme-new .checkbox-primary input[type="checkbox"]:checked + label::before {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

body.theme-new .checkbox-primary input[type="checkbox"]:checked + label::after {
    color: var(--bg-body);
}

body.theme-new .radio label::before {
    background: var(--input-bg);
    border-color: var(--input-border);
}

body.theme-new .radio-primary input[type="radio"]:checked + label::before {
    border-color: var(--primary-color);
}

body.theme-new .radio-primary input[type="radio"]:checked + label::after {
    background: var(--primary-color);
}

/* Native checkbox / radio fallback */
body.theme-new input[type="checkbox"],
body.theme-new input[type="radio"] {
    accent-color: var(--primary-color);
}

/* Textarea */
body.theme-new textarea.form-control {
    min-height: 80px;
}

@media (prefers-reduced-motion: reduce) {
    body.theme-new .form-control,
    body.theme-new .bootstrap-select > .btn,
    body.theme-new .select2-container--default .select2-selection {
        transition: none !important;
    }
}
