/**

 * حقول الإدخال — حد موحّد 2px (يتبع ألوان الثيم)

 */

:root,

[data-theme="light"] {

    --input-border: #566a7f;

    --input-border-focus: #1a78c2;

    --input-focus-ring: rgba(26, 120, 194, 0.2);

    --mc-input-height-scale: 1.5;

}



[data-theme="dark"] {

    --input-border: #6d8498;

    --input-border-focus: #5ba3e8;

    --input-focus-ring: rgba(91, 163, 232, 0.28);

    --mc-input-height-scale: 1.5;

}



/* حقول الإدخال والبحث - ضمان وضوح الخلفية والنص في الوضعين الفاتح والداكن */
input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="image"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not([type="color"]),
textarea,
select,
.form-control,
.form-select,
.sidebar-search-input,
.select2-search__field {
    background-color: var(--card-bg, #ffffff) !important;
    color: var(--text-primary, #1a1a1a) !important;
}

/* ==========================================================================
   خانات الاختيار (Checkboxes) — دعم علامة الصح باللون الأسود في الفاتح والأبيض في الداكن
   ========================================================================== */

input[type="checkbox"],
.form-check-input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 1.15em;
    height: 1.15em;
    border: 2px solid var(--input-border, #566a7f) !important;
    border-radius: 4px;
    background-color: var(--card-bg, #ffffff) !important;
    background-repeat: no-repeat;
    background-position: center;
    background-size: 85% 85%;
    cursor: pointer;
    vertical-align: middle;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

input[type="checkbox"]:focus,
.form-check-input[type="checkbox"]:focus {
    border-color: var(--input-border-focus, #1a78c2) !important;
    box-shadow: 0 0 0 2px var(--input-focus-ring) !important;
    outline: none;
}

/* الوضع الفاتح: علامة الصح باللون الأسود داخل المربع */
input[type="checkbox"]:not(.form-switch *):not(.form-switch):checked,
.form-check-input[type="checkbox"]:not(.form-switch *):not(.form-switch):checked,
[data-theme="light"] input[type="checkbox"]:not(.form-switch *):not(.form-switch):checked,
[data-theme="light"] .form-check-input[type="checkbox"]:not(.form-switch *):not(.form-switch):checked {
    background-color: var(--card-bg, #ffffff) !important;
    border-color: var(--input-border, #566a7f) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23000000' stroke-linecap='round' stroke-linejoin='round' stroke-width='3.2' d='m4 10 4 4 8-8'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 85% 85% !important;
}

/* الوضع الداكن: علامة الصح باللون الأبيض داخل المربع */
[data-theme="dark"] input[type="checkbox"]:not(.form-switch *):not(.form-switch):checked,
[data-theme="dark"] .form-check-input[type="checkbox"]:not(.form-switch *):not(.form-switch):checked {
    background-color: var(--card-bg, #1e2a38) !important;
    border-color: var(--input-border-focus, #5ba3e8) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3.2' d='m4 10 4 4 8-8'/%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 85% 85% !important;
}

/* حالة Indeterminate (الشرطة): أسود في الفاتح، أبيض في الداكن */
input[type="checkbox"]:not(.form-switch *):not(.form-switch):indeterminate,
.form-check-input[type="checkbox"]:not(.form-switch *):not(.form-switch):indeterminate,
[data-theme="light"] input[type="checkbox"]:not(.form-switch *):not(.form-switch):indeterminate,
[data-theme="light"] .form-check-input[type="checkbox"]:not(.form-switch *):not(.form-switch):indeterminate {
    background-color: var(--card-bg, #ffffff) !important;
    border-color: var(--input-border, #566a7f) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23000000' stroke-linecap='round' stroke-linejoin='round' stroke-width='3.2' d='M5 10h10'/%3e%3c/svg%3e") !important;
}

[data-theme="dark"] input[type="checkbox"]:not(.form-switch *):not(.form-switch):indeterminate,
[data-theme="dark"] .form-check-input[type="checkbox"]:not(.form-switch *):not(.form-switch):indeterminate {
    background-color: var(--card-bg, #1e2a38) !important;
    border-color: var(--input-border-focus, #5ba3e8) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3.2' d='M5 10h10'/%3e%3c/svg%3e") !important;
}

/* مفاتيح التبديل (Switches) - الحفاظ على شكل المفتاح */
.form-switch .form-check-input {
    width: 2.2em !important;
    height: 1.2em !important;
    border-radius: 2em !important;
    background-position: left center !important;
    background-size: contain !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba(0,0,0,0.45)'/%3e%3c/svg%3e") !important;
}

[data-theme="dark"] .form-switch .form-check-input {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba(255,255,255,0.65)'/%3e%3c/svg%3e") !important;
}

.form-switch .form-check-input:checked {
    background-position: right center !important;
    background-color: var(--primary, #1a78c2) !important;
    border-color: var(--primary, #1a78c2) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e") !important;
}

input::placeholder,
textarea::placeholder,
.form-control::placeholder,
.sidebar-search-input::placeholder,
.select2-search__field::placeholder {
    color: var(--text-muted, #6c757d) !important;
    opacity: 0.85;
}

/* دعم الإكمال التلقائي والمتصفح (Autofill) في الوضع الداكن */
[data-theme="dark"] input:-webkit-autofill,
[data-theme="dark"] input:-webkit-autofill:hover,
[data-theme="dark"] input:-webkit-autofill:focus,
[data-theme="dark"] textarea:-webkit-autofill,
[data-theme="dark"] textarea:-webkit-autofill:hover,
[data-theme="dark"] textarea:-webkit-autofill:focus,
[data-theme="dark"] select:-webkit-autofill,
[data-theme="dark"] select:-webkit-autofill:hover,
[data-theme="dark"] select:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary, #e8eaed) !important;
    -webkit-box-shadow: 0 0 0px 1000px var(--card-bg, #1e2a38) inset !important;
    transition: background-color 5000s ease-in-out 0s;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="image"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not([type="color"]),

textarea,

select,

.form-control,

.form-select,

.sidebar-search-input,

.select2-container--bootstrap-5 .select2-selection,

.select2-container--default .select2-selection--single,

.select2-container--default .select2-selection--multiple,

.select2-search__field {

    border: 2px solid var(--input-border) !important;

}



.form-control:focus,

.form-select:focus,

.sidebar-search-input:focus,

input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="image"]):not([type="hidden"]):not([type="file"]):not([type="range"]):not([type="color"]):focus,

textarea:focus,

select:focus,

.select2-container--bootstrap-5.select2-container--focus .select2-selection,

.select2-container--default.select2-container--focus .select2-selection--single,

.select2-container--default.select2-container--focus .select2-selection--multiple {

    border-color: var(--input-border-focus) !important;

    box-shadow: 0 0 0 2px var(--input-focus-ring) !important;

}



/* Select2 — نفس شكل form-control / form-select */

.select2-container--bootstrap-5 .select2-selection--single,

.select2-container--bootstrap-5 .select2-selection--multiple,

.select2-container--default .select2-selection--single,

.select2-container--default .select2-selection--multiple {

    min-height: calc((1.2em + .3rem + 2px) * var(--mc-input-height-scale, 1.5)) !important;

    height: auto !important;

    padding-top: calc(3px * var(--mc-input-height-scale, 1.5)) !important;

    padding-bottom: calc(3px * var(--mc-input-height-scale, 1.5)) !important;

    padding-left: 10px !important;

    padding-right: 10px !important;

    border-radius: 4px !important;

    background-color: var(--card-bg, #fff) !important;

    color: var(--text-primary, #212529) !important;

    display: flex !important;

    align-items: center !important;

    box-sizing: border-box !important;

}



.select2-container--bootstrap-5 .select2-selection__rendered,

.select2-container--default .select2-selection__rendered {

    padding: 0 !important;

    line-height: 1.25 !important;

    font-size: .875rem !important;

    color: inherit !important;

}



.select2-container--bootstrap-5 .select2-selection--single .select2-selection__arrow,

.select2-container--default .select2-selection--single .select2-selection__arrow {

    height: 100% !important;

    top: 0 !important;

}



.select2-container--bootstrap-5 .select2-selection__placeholder {

    color: var(--text-muted, #6c757d) !important;

}



.select2-container--bootstrap-5.select2-container--disabled .select2-selection,

.select2-container--default.select2-container--disabled .select2-selection--single,

.select2-container--default.select2-container--disabled .select2-selection--multiple {

    background-color: var(--input-bg, #e9ecef) !important;

    color: var(--text-muted, #6c757d) !important;

}



select.form-select-sm.select2 + .select2-container .select2-selection--single,

select.form-select-sm.select2 + .select2-container .select2-selection--multiple,

select.form-control-sm.select2 + .select2-container .select2-selection--single,

select.form-control-sm.select2 + .select2-container .select2-selection--multiple {

    min-height: calc((1.1em + .2rem + 2px) * var(--mc-input-height-scale, 1.5)) !important;

    padding-top: calc(2px * var(--mc-input-height-scale, 1.5)) !important;

    padding-bottom: calc(2px * var(--mc-input-height-scale, 1.5)) !important;

    padding-left: 8px !important;

    padding-right: 8px !important;

}



select.form-select-sm.select2 + .select2-container .select2-selection__rendered,

select.form-control-sm.select2 + .select2-container .select2-selection__rendered {

    font-size: .8125rem !important;

    line-height: 1.2 !important;

}



.input-group > .select2-container {

    flex: 1 1 auto;

    min-width: 0;

    width: 1% !important;

}



.select2-dropdown {

    border-radius: 4px;

    border: 2px solid var(--input-border);

    background-color: var(--card-bg, #fff);

    color: var(--text-primary, #212529);

    overflow: hidden;

    z-index: 2000;

}



/* قائمة النتائج: لا تتمدد خارج الشاشة — يُضبط ديناميكياً أيضاً من select2-global.js */

.select2-results > .select2-results__options {

    max-height: min(280px, 45vh);

    overflow-y: auto;

}



.select2-results__option {

    padding: 4px 10px;

    font-size: .875rem;

    line-height: 1.25;

}



.select2-results__option--highlighted.select2-results__option--selectable {

    background-color: var(--input-border-focus, #1a78c2) !important;

    color: #fff !important;

}



.select2-search--dropdown .select2-search__field {

    border-radius: 4px !important;

    padding: 3px 10px !important;

    min-height: calc((1.2em + .3rem + 2px) * var(--mc-input-height-scale, 1.5));

    font-size: .875rem;

    line-height: 1.25;

    background-color: var(--card-bg, #fff) !important;

    color: var(--text-primary, #212529) !important;

}

/* تحسين خيارات قائمة Select2 وتوافقها مع الوضع الداكن */
.select2-results__option {
    background-color: var(--card-bg, #fff);
    color: var(--text-primary, #212529);
}

.select2-container--default .select2-results__option--selected,
.select2-container--bootstrap-5 .select2-results__option--selected {
    background-color: var(--sidebar-hover, #2d3d4f) !important;
    color: var(--text-primary, #e8eaed) !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--bootstrap-5 .select2-results__option--highlighted[aria-selected] {
    background-color: var(--input-border-focus, #5ba3e8) !important;
    color: #fff !important;
}

/* ==========================================================================
   ارتفاع حقول الإدخال — +50% (على Bootstrap والتنسيقات المدمجة)
   ========================================================================== */

.form-control:not(textarea):not([type="color"]),
.form-select,
.sidebar-search-input,
input[type="text"],
input[type="search"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
select:not([multiple]) {
    min-height: calc((1.2em + 0.3rem + 4px) * var(--mc-input-height-scale, 1.5)) !important;
    padding-top: calc(3px * var(--mc-input-height-scale, 1.5)) !important;
    padding-bottom: calc(3px * var(--mc-input-height-scale, 1.5)) !important;
    height: auto !important;
}

.form-control-sm:not(textarea),
.form-select-sm {
    min-height: calc((1.1em + 0.2rem + 4px) * var(--mc-input-height-scale, 1.5)) !important;
    padding-top: calc(2px * var(--mc-input-height-scale, 1.5)) !important;
    padding-bottom: calc(2px * var(--mc-input-height-scale, 1.5)) !important;
    height: auto !important;
}

.form-control-lg:not(textarea),
.form-select-lg {
    min-height: calc((1.5em + 1rem + 4px) * var(--mc-input-height-scale, 1.5)) !important;
    padding-top: calc(0.5rem * var(--mc-input-height-scale, 1.5)) !important;
    padding-bottom: calc(0.5rem * var(--mc-input-height-scale, 1.5)) !important;
    height: auto !important;
}

textarea.form-control {
    min-height: calc(4.5rem * var(--mc-input-height-scale, 1.5)) !important;
    padding-top: calc(0.375rem * var(--mc-input-height-scale, 1.5)) !important;
    padding-bottom: calc(0.375rem * var(--mc-input-height-scale, 1.5)) !important;
}

.doc-invoice-form .form-control:not(textarea),
.doc-invoice-form .form-select,
.doc-invoice-form .select2-container .select2-selection--single,
.doc-invoice-form .select2-container .select2-selection--multiple {
    min-height: calc((1.15em + 0.28rem + 2px) * var(--mc-input-height-scale, 1.5)) !important;
    height: auto !important;
}

.doc-invoice-form .form-control-sm,
.doc-invoice-form .form-select-sm,
.doc-invoice-form .table-sales-items .form-control-sm {
    min-height: calc((1.05em + 0.18rem + 2px) * var(--mc-input-height-scale, 1.5)) !important;
    height: auto !important;
}

.doc-header-compact .form-control,
.doc-header-compact .form-select {
    min-height: calc((1.15em + 0.28rem + 2px) * var(--mc-input-height-scale, 1.5)) !important;
    height: auto !important;
}
