/* Controls and artwork are not selectable text. Editable fields remain selectable. */
html body :is(button, select, option, [role="button"], [role="combobox"], [role="option"],
    .crm-select-trigger, .crm-select-option, .purchase-select-trigger, .purchase-select-option,
    img, svg, crm-icon),
html body :is(button, [role="button"], [role="combobox"], [role="option"],
    .crm-select-trigger, .crm-select-option, .purchase-select-trigger, .purchase-select-option) * {
    -webkit-user-select: none !important;
    user-select: none !important;
}
html body :is(img, svg, crm-icon) { -webkit-user-drag: none; }
html body :is(input:not([type="button"]):not([type="submit"]):not([type="reset"]), textarea,
    [contenteditable="true"], [contenteditable="true"] *) {
    -webkit-user-select: text !important;
    user-select: text !important;
}

/* Shared field focus: existing field border + a separated outer ring.
   Important is intentional: module-level focus rules must not hide this ring. */
:is(
    input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="button"]):not([type="submit"]):not([type="reset"]),
    textarea
):not(:where(.crm-search input, .search-box input, .purchases-search-box input, .warehouse-search input, .orders-search-box input, .directory-search-box input)):not(:disabled):not([aria-disabled="true"]):focus {
    outline: 2px solid var(--crm-field-focus-color, var(--crm-blue, #4169e1)) !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
}

.purchase-field--attention {
    --crm-field-focus-color: #d4a017;
}

/* Project-wide borderless actions/selects. Transparent borders keep layout stable.
   Actions are excluded from Tab navigation. Field focus above stays intact. */
html body :is(button, select, input[type="button"], input[type="submit"], input[type="reset"],
    [role="button"], [role="combobox"], .crm-select-trigger, .purchase-select-trigger,
    .order-date-trigger) {
    border-color: transparent !important;
    outline: none !important;
}
html body :is(button, select, input[type="button"], input[type="submit"], input[type="reset"],
    [role="button"], [role="combobox"], .crm-select-trigger, .purchase-select-trigger,
    .order-date-trigger):focus {
    box-shadow: none !important;
}
html body button.calendar-day--today { box-shadow: none; }

:is([aria-invalid="true"], .client-phone--error, .order-card-native-select--error,
    .order-field--attention, .purchase-price-required, .purchase-request-input--error) {
    --crm-field-focus-color: #dc2626;
}

/* Search controls have their visible border on the wrapper. */
:is(.search-box, .purchases-search-box, .warehouse-search, .orders-search-box, .directory-search-box):focus-within {
    outline: 2px solid var(--crm-blue, #4169e1) !important;
    outline-offset: 2px !important;
    box-shadow: none !important;
}
:is(.search-box, .purchases-search-box, .warehouse-search, .orders-search-box, .directory-search-box) input:focus {
    outline: none !important;
}

@media (forced-colors: active) {
    :root { --crm-blue: Highlight; }
    :is([aria-invalid="true"], .client-phone--error, .order-card-native-select--error,
        .order-field--attention, .purchase-price-required, .purchase-request-input--error,
        .purchase-field--attention) { --crm-field-focus-color: Highlight; }
}

:is(.search-box, .purchases-search-box, .warehouse-search, .orders-search-box, .directory-search-box):focus-within { box-shadow: 0 0 12px #48bfff55 !important; }
/* Search focus matches the live Clients reference in every module. */
html body :is(.search-box, .purchases-search-box, .warehouse-search, .orders-search-box, .directory-search-box):focus-within {
    outline-color: #83baff !important;
    box-shadow: none !important;
}
