/**
 * CRM Material Design form system — Google Material outlined text fields.
 * Label rests inside the box; on focus/fill it sits in the border notch (MUI-style).
 */

:root {
    --crm-m3-field-height: 3.5rem;
    --crm-m3-field-height-sm: 3.25rem;
    --crm-m3-field-height-grid: 3.25rem;
    --crm-m3-radius: 0.25rem;
    --crm-m3-radius-sm: 0.25rem;
    --crm-m3-padding-x: 0.75rem;
    --crm-m3-label-rest: 1rem;
    --crm-m3-label-float: 0.75rem;
    --crm-m3-outline: #c4c7cf;
    --crm-m3-outline-hover: #8e9199;
    --crm-m3-surface: #fff;
    --crm-m3-on-surface: #1f2937;
    --crm-m3-on-surface-variant: #5f6368;
    --crm-m3-primary: var(--primary, #0c83ff);
    --crm-m3-primary-rgb: var(--primary-rgb, 12, 131, 255);
    --crm-m3-error: var(--danger, #dc3545);
    --crm-m3-success: #059669;
    --crm-m3-disabled-bg: #f3f4f6;
    --crm-m3-disabled-text: #9ca3af;
    --crm-m3-transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --crm-m3-focus-ring: 0 0 0 0.125rem rgba(var(--crm-m3-primary-rgb), 0.28);
}

/* Legacy rich-text / opt-out regions — no Material input chrome */
.crm-material-scope .no-material-field textarea.tinymce-textarea,
.crm-material-scope .no-material-field .tinymce-textarea-plain,
.crm-material-scope #task_description_section textarea.tinymce-textarea {
    min-height: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
}

.crm-material-scope .no-material-field .crm-field {
    display: none;
}

/* ---- Scopes ---- */
.crm-material-scope .crm-field,
.modal .crm-field,
.content .crm-field,
.right-sidebar .crm-field,
.reminders-side-panel .crm-field,
.crm-settings-page .crm-field,
.webform-fields-wrapper .crm-field,
.login-form .crm-field,
.signup-form .crm-field {
    position: relative;
    display: block;
    width: 100%;
    margin-bottom: 0.25rem;
    font-family: inherit;
}

/* Legacy Bootstrap label hidden after enhancement */
.crm-material-enhanced > label.crm-material-label-legacy,
.crm-material-enhanced > label.col-form-label.crm-material-label-legacy,
.crm-material-enhanced > label.control-label.crm-material-label-legacy,
.crm-material-enhanced > label.form-label.crm-material-label-legacy,
.crm-material-enhanced.crm-form-2col-cell > label.crm-material-label-legacy,
.crm-material-enhanced.crm-form-3col-cell > label.crm-material-label-legacy {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.crm-material-enhanced > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}

.crm-material-enhanced.crm-form-2col-cell > label,
.crm-material-enhanced.crm-form-3col-cell > label {
    margin-bottom: 0 !important;
}

.crm-form-2col-grid .crm-field,
.crm-form-3col-grid .crm-field {
    --crm-m3-field-height: var(--crm-m3-field-height-grid);
}

/* ---- Outlined field shell ---- */
.crm-field--outlined .crm-input,
.crm-field--outlined .form-control.crm-input {
    display: block;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    min-height: var(--crm-m3-field-height);
    padding: 1rem var(--crm-m3-padding-x);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--crm-m3-on-surface);
    background-color: var(--crm-m3-surface);
    border: 1px solid var(--crm-m3-outline);
    border-radius: var(--crm-m3-radius);
    box-shadow: none;
    outline: none;
    transition:
        border-color var(--crm-m3-transition),
        box-shadow var(--crm-m3-transition),
        background-color var(--crm-m3-transition);
    -webkit-appearance: none;
    appearance: none;
}

.crm-field--outlined .form-control-sm.crm-input,
.crm-field--outlined .crm-input.form-control-sm {
    min-height: var(--crm-m3-field-height-sm);
    padding: 0.875rem var(--crm-m3-padding-x);
    font-size: 0.875rem;
    line-height: 1.4;
}

.crm-field--outlined.crm-field--filled .crm-input,
.crm-field--outlined.crm-field--focused .crm-input,
.crm-field--outlined.crm-field--open .crm-input,
.crm-field--outlined .crm-input:focus,
.crm-field--outlined .crm-input:not(:placeholder-shown) {
    padding-top: 1.0625rem;
    padding-bottom: 0.4375rem;
}

.crm-field--outlined textarea.crm-input,
.crm-field--outlined textarea.form-control.crm-input {
    min-height: 6.5rem;
    padding-top: 1.25rem;
    resize: vertical;
}

.crm-field--outlined.crm-field--filled textarea.crm-input,
.crm-field--outlined.crm-field--focused textarea.crm-input,
.crm-field--outlined textarea.crm-input:focus {
    padding-top: 1.375rem;
}

/* ---- Outlined floating label (notch on border) ---- */
.crm-field--outlined .crm-field__label {
    position: absolute;
    left: calc(var(--crm-m3-padding-x) - 0.125rem);
    top: 50%;
    z-index: 3;
    max-width: calc(100% - 2.5rem);
    margin: 0;
    padding: 0 0.25rem;
    font-size: var(--crm-m3-label-rest);
    font-weight: 400;
    line-height: 1.2;
    color: var(--crm-m3-on-surface-variant);
    background: transparent;
    border-radius: 0.125rem;
    transform: translateY(-50%);
    transform-origin: left center;
    transition:
        top var(--crm-m3-transition),
        transform var(--crm-m3-transition),
        font-size var(--crm-m3-transition),
        color var(--crm-m3-transition),
        background-color var(--crm-m3-transition);
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-field--outlined.crm-field--with-icon .crm-field__label {
    left: 2.5rem;
}

.crm-field__label .crm-field__required {
    color: var(--crm-m3-error);
    font-weight: 600;
}

/* Label in border notch when focused, filled, or select open */
.crm-field--outlined.crm-field--focused .crm-field__label,
.crm-field--outlined.crm-field--filled .crm-field__label,
.crm-field--outlined.crm-field--open .crm-field__label,
.crm-field--outlined .crm-input:focus ~ .crm-field__label,
.crm-field--outlined .crm-input:not(:placeholder-shown) ~ .crm-field__label {
    top: 0;
    transform: translateY(-50%) scale(1);
    font-size: var(--crm-m3-label-float);
    font-weight: 400;
    background: var(--crm-m3-surface);
    color: var(--crm-m3-on-surface-variant);
}

.crm-field--outlined.crm-field--focused .crm-field__label,
.crm-field--outlined.crm-field--open .crm-field__label,
.crm-field--outlined .crm-input:focus ~ .crm-field__label {
    color: var(--crm-m3-primary);
}

/* ---- Leading icon (auth / feedback fields) ---- */
.crm-field__icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    z-index: 3;
    transform: translateY(-50%);
    font-size: 1.125rem;
    line-height: 1;
    color: var(--crm-m3-on-surface-variant);
    pointer-events: none;
}

.crm-field--outlined.crm-field--with-icon .crm-input,
.crm-field--outlined.crm-field--with-icon .form-control.crm-input {
    padding-left: 2.75rem;
}

.crm-field--outlined.crm-field--with-icon.crm-field--filled .crm-input,
.crm-field--outlined.crm-field--with-icon.crm-field--focused .crm-input,
.crm-field--outlined.crm-field--with-icon.crm-field--open .crm-input,
.crm-field--outlined.crm-field--with-icon .crm-input:focus,
.crm-field--outlined.crm-field--with-icon .crm-input:not(:placeholder-shown) {
    padding-left: 2.75rem;
}

/* Chrome autofill — keep surface color, avoid yellow overlap on auth fields */
.crm-field--outlined .crm-input:-webkit-autofill,
.crm-field--outlined .crm-input:-webkit-autofill:hover,
.crm-field--outlined .crm-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--crm-m3-on-surface);
    box-shadow: 0 0 0 1000px var(--crm-m3-surface) inset;
    transition: background-color 99999s ease-out;
}

/* ---- Hover / focus ---- */
.crm-field--outlined:not(.crm-field--disabled):not(.crm-field--readonly) .crm-input:hover {
    border-color: var(--crm-m3-outline-hover);
}

.crm-field--outlined.crm-field--focused .crm-input,
.crm-field--outlined .crm-input:focus {
    border: 2px solid var(--crm-m3-primary) !important;
    padding-left: calc(var(--crm-m3-padding-x) - 1px);
    padding-right: calc(var(--crm-m3-padding-x) - 1px);
    box-shadow: none !important;
}

.crm-field--outlined.crm-field--focused.crm-field--filled .crm-input,
.crm-field--outlined.crm-field--focused .crm-input:focus,
.crm-field--outlined.crm-field--filled .crm-input:focus {
    padding-top: calc(1.0625rem - 1px);
    padding-bottom: calc(0.4375rem - 1px);
}

/* ---- Disabled ---- */
.crm-field--disabled .crm-input,
.crm-field .crm-input:disabled {
    background-color: var(--crm-m3-disabled-bg);
    color: var(--crm-m3-disabled-text);
    border-color: var(--crm-m3-outline);
    cursor: not-allowed;
    opacity: 1;
}

.crm-field--disabled .crm-field__label {
    color: var(--crm-m3-disabled-text);
}

/* ---- Read-only ---- */
.crm-field--readonly .crm-input,
.crm-field .crm-input[readonly] {
    background-color: var(--crm-m3-disabled-bg);
    border-style: dashed;
    cursor: default;
}

/* ---- Error ---- */
.crm-field--error .crm-input,
.crm-field .crm-input.error,
.crm-field .crm-input.is-invalid {
    border-color: var(--crm-m3-error) !important;
    box-shadow: 0 0 0 0.125rem rgba(220, 53, 69, 0.18);
}

.crm-field--error .crm-field__label,
.crm-field--error.crm-field--focused .crm-field__label {
    color: var(--crm-m3-error);
}

.crm-field__error,
.crm-field__error label.error {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.35;
    color: var(--crm-m3-error);
}

.crm-field__error:empty {
    display: none;
    margin: 0;
}

/* ---- Success ---- */
.crm-field--success .crm-input,
.crm-field .crm-input.valid {
    border-color: var(--crm-m3-success);
    box-shadow: 0 0 0 0.125rem rgba(5, 150, 105, 0.15);
}

.crm-field--success .crm-field__label {
    color: var(--crm-m3-success);
}

/* ---- Helper text ---- */
.crm-field__supporting {
    display: block;
    margin-top: 0.375rem;
    font-size: 0.8125rem;
    line-height: 1.35;
    color: var(--crm-m3-on-surface-variant);
}

.crm-field__supporting:empty {
    display: none;
}

/* ---- Select2 inside material field ---- */
.crm-field .select2-container {
    width: 100% !important;
    display: block;
}

.crm-field--outlined .select2-container .select2-selection--single {
    display: flex !important;
    align-items: center !important;
    min-height: var(--crm-m3-field-height) !important;
    height: var(--crm-m3-field-height) !important;
    border: 1px solid var(--crm-m3-outline) !important;
    border-radius: var(--crm-m3-radius) !important;
    background: var(--crm-m3-surface) !important;
    padding: 0 2.25rem 0 var(--crm-m3-padding-x) !important;
    box-shadow: none !important;
    transition: border-color var(--crm-m3-transition), border-width var(--crm-m3-transition);
}

.crm-field--outlined.crm-field--filled .select2-container .select2-selection--single,
.crm-field--outlined.crm-field--focused .select2-container .select2-selection--single,
.crm-field--outlined.crm-field--open .select2-container .select2-selection--single {
    padding-top: 0.5625rem !important;
    padding-bottom: 0.125rem !important;
    align-items: center !important;
}

.crm-field--outlined .form-control-sm + .select2-container .select2-selection--single,
.crm-field--outlined select.form-control-sm ~ .select2-container .select2-selection--single {
    min-height: var(--crm-m3-field-height-sm) !important;
    height: var(--crm-m3-field-height-sm) !important;
    font-size: 0.875rem !important;
}

.crm-field--outlined .select2-container .select2-selection--single .select2-selection__rendered {
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    min-height: 100%;
    line-height: 1.25 !important;
    font-size: inherit !important;
    color: var(--crm-m3-on-surface) !important;
}

.crm-field--outlined .select2-container .select2-selection--single .select2-selection__placeholder {
    color: transparent !important;
}

.crm-field--outlined .select2-container .select2-selection--single .select2-selection__arrow {
    top: 50% !important;
    transform: translateY(-50%) !important;
    height: auto !important;
}

.crm-field--outlined.crm-field--focused .select2-container .select2-selection--single,
.crm-field--outlined.crm-field--open .select2-container .select2-selection--single {
    border: 2px solid var(--crm-m3-primary) !important;
    padding-left: calc(var(--crm-m3-padding-x) - 1px) !important;
    box-shadow: none !important;
}

.crm-field--outlined .select2-container .select2-selection--multiple {
    min-height: var(--crm-m3-field-height) !important;
    border: 1px solid var(--crm-m3-outline) !important;
    border-radius: var(--crm-m3-radius) !important;
    background: var(--crm-m3-surface) !important;
    padding: 0.4375rem 1.75rem 0.4375rem calc(var(--crm-m3-padding-x) - 1px) !important;
    box-shadow: none !important;
}

.crm-field--outlined.crm-field--filled .select2-container .select2-selection--multiple,
.crm-field--outlined.crm-field--focused .select2-container .select2-selection--multiple,
.crm-field--outlined.crm-field--open .select2-container .select2-selection--multiple {
    padding-top: 0.875rem !important;
}

.crm-field--outlined.crm-field--focused .select2-container .select2-selection--multiple,
.crm-field--outlined.crm-field--open .select2-container .select2-selection--multiple {
    border: 2px solid var(--crm-m3-primary) !important;
    box-shadow: none !important;
}

.crm-field--error .select2-container .select2-selection--single,
.crm-field .select2-container.error .select2-selection--single {
    border-color: var(--crm-m3-error) !important;
    box-shadow: 0 0 0 0.125rem rgba(220, 53, 69, 0.18) !important;
}

.crm-field--success .select2-container .select2-selection--single,
.crm-field .select2-container.valid .select2-selection--single {
    border-color: var(--crm-m3-success) !important;
}

.crm-field .select2-hidden-accessible {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    clip: rect(0, 0, 0, 0) !important;
}

/* ---- Native select (non-Select2) ---- */
.crm-field select.crm-input {
    padding-right: 2.5rem;
    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='%235f6368' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    background-size: 14px 10px;
}

/* ---- File input ---- */
.crm-field--file .crm-input[type="file"] {
    padding: 0.875rem var(--crm-m3-padding-x);
    min-height: var(--crm-m3-field-height);
    cursor: pointer;
}

.crm-field--file .crm-input[type="file"]::file-selector-button {
    margin-right: 0.75rem;
    padding: 0.375rem 0.875rem;
    border: 0;
    border-radius: 50rem;
    background: rgba(var(--crm-m3-primary-rgb), 0.12);
    color: var(--crm-m3-primary);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--crm-m3-transition);
}

.crm-field--file .crm-input[type="file"]::file-selector-button:hover {
    background: rgba(var(--crm-m3-primary-rgb), 0.2);
}

/* ---- Date / time pickers ---- */
.crm-field .crm-input.pickadate,
.crm-field .crm-input.pickatime {
    cursor: pointer;
}

/* ---- Input groups: preserve layout, material inside ---- */
.crm-material-enhanced .input-group .crm-field {
    flex: 1 1 auto;
    margin-bottom: 0;
}

.crm-material-enhanced .input-group .crm-field .crm-input {
    border-radius: 0;
}

.crm-material-enhanced .input-group > .crm-field:first-child .crm-input {
    border-top-left-radius: var(--crm-m3-radius);
    border-bottom-left-radius: var(--crm-m3-radius);
}

.crm-material-enhanced .input-group > .crm-field:last-child .crm-input {
    border-top-right-radius: var(--crm-m3-radius);
    border-bottom-right-radius: var(--crm-m3-radius);
}

/* ---- Checkbox / switch rows untouched ---- */
.crm-material-enhanced.form-group-checkbox .crm-field,
.form-group-checkbox .crm-field {
    display: none;
}

/* ---- Spacing between enhanced groups ---- */
.crm-material-enhanced.form-group,
.crm-material-enhanced.form-group.row,
.modal .crm-material-enhanced.form-group.row,
.content .crm-material-enhanced.form-group.row {
    margin-bottom: 1.125rem;
}

/* ---- Unenhanced fallback: still modernize bare controls in scope ---- */
.crm-material-scope .modal .form-control:not(.crm-input),
.crm-material-scope .content .form-control:not(.crm-input),
.crm-material-scope .right-sidebar .form-control:not(.crm-input) {
    min-height: var(--crm-m3-field-height-sm);
    border-radius: var(--crm-m3-radius-sm);
    border-color: var(--crm-m3-outline);
    transition: border-color var(--crm-m3-transition), box-shadow var(--crm-m3-transition);
}

.crm-material-scope .modal .form-control:not(.crm-input):focus,
.crm-material-scope .content .form-control:not(.crm-input):focus {
    border-color: var(--crm-m3-primary);
    box-shadow: var(--crm-m3-focus-ring);
}

.crm-form-2col-grid .crm-material-enhanced.crm-form-2col-cell,
.crm-form-3col-grid .crm-material-enhanced.crm-form-3col-cell {
    margin-bottom: 0 !important;
}

/* Beat modal grid compact Select2 rules (limitless-crm-forms loads before this file) */
.modal .crm-form-2col-grid .crm-field--outlined .select2-container .select2-selection--single,
.modal .crm-form-3col-grid .crm-field--outlined .select2-container .select2-selection--single,
.modal .crm-task-form .crm-field--outlined .select2-container .select2-selection--single {
    display: flex !important;
    align-items: center !important;
    min-height: var(--crm-m3-field-height) !important;
    height: var(--crm-m3-field-height) !important;
    max-height: none !important;
    padding: 0 2.25rem 0 var(--crm-m3-padding-x) !important;
    font-size: 1rem !important;
}

.modal .crm-form-2col-grid .crm-field--outlined.crm-field--filled .select2-container .select2-selection--single,
.modal .crm-form-3col-grid .crm-field--outlined.crm-field--filled .select2-container .select2-selection--single,
.modal .crm-task-form .crm-field--outlined.crm-field--filled .select2-container .select2-selection--single,
.modal .crm-form-2col-grid .crm-field--outlined.crm-field--focused .select2-container .select2-selection--single,
.modal .crm-form-3col-grid .crm-field--outlined.crm-field--focused .select2-container .select2-selection--single,
.modal .crm-task-form .crm-field--outlined.crm-field--focused .select2-container .select2-selection--single,
.modal .crm-form-2col-grid .crm-field--outlined.crm-field--open .select2-container .select2-selection--single,
.modal .crm-form-3col-grid .crm-field--outlined.crm-field--open .select2-container .select2-selection--single,
.modal .crm-task-form .crm-field--outlined.crm-field--open .select2-container .select2-selection--single {
    align-items: center !important;
    padding-top: 0.5625rem !important;
    padding-bottom: 0.125rem !important;
}

.modal .crm-form-2col-grid .crm-field--outlined .select2-container .select2-selection--single .select2-selection__rendered,
.modal .crm-form-3col-grid .crm-field--outlined .select2-container .select2-selection--single .select2-selection__rendered,
.modal .crm-task-form .crm-field--outlined .select2-container .select2-selection--single .select2-selection__rendered {
    font-size: 1rem !important;
    line-height: 1.25 !important;
    display: flex !important;
    align-items: center !important;
    min-height: 100%;
}

.modal .crm-form-2col-grid .crm-field--outlined .form-control-sm + .select2-container .select2-selection--single,
.modal .crm-form-3col-grid .crm-field--outlined select.form-control-sm ~ .select2-container .select2-selection--single,
.modal .crm-task-form .crm-field--outlined select.form-control-sm ~ .select2-container .select2-selection--single {
    min-height: var(--crm-m3-field-height-sm) !important;
    height: var(--crm-m3-field-height-sm) !important;
    font-size: 0.875rem !important;
}

.modal .crm-form-2col-grid .crm-field--outlined .select2-container .select2-selection--multiple,
.modal .crm-form-3col-grid .crm-field--outlined .select2-container .select2-selection--multiple,
.modal .crm-task-form .crm-field--outlined .select2-container .select2-selection--multiple {
    min-height: var(--crm-m3-field-height) !important;
    max-height: none !important;
    padding: 0.4375rem 1.75rem 0.4375rem var(--crm-m3-padding-x) !important;
}
