/* Tom Select — RTL fixes + searchable dropdown */
.field { position: relative; overflow: visible; min-width: 0; }
.card, .filter-grid, .form-grid { overflow: visible; }

.ts-wrapper {
  width: 100% !important;
  direction: rtl;
  position: relative;
  display: block;
}

.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
  min-height: 40px !important;
  height: auto !important;
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 6px;
  border: 1px solid #e2e6ed !important;
  border-radius: 8px !important;
  background: #f8f9fb !important;
  background-image: none !important;
  font-family: 'Cairo', system-ui, sans-serif !important;
  font-size: 13px !important;
  /* RTL: نص يمين + سهم يسار */
  padding: 0 14px 0 38px !important;
  box-shadow: none !important;
  cursor: pointer !important;
  width: 100% !important;
}

/* سهم القائمة — يسار في RTL */
.ts-wrapper.single .ts-control::after {
  content: " " !important;
  display: block !important;
  position: absolute !important;
  top: 50% !important;
  left: 14px !important;
  right: auto !important;
  margin-top: -3px !important;
  border: 5px solid transparent !important;
  border-top-color: #9ca3af !important;
  border-bottom: 0 !important;
  width: 0 !important;
  height: 0 !important;
  pointer-events: none !important;
}

.ts-wrapper.single.dropdown-active .ts-control::after {
  margin-top: -4px !important;
  border-top-color: transparent !important;
  border-bottom-color: #9ca3af !important;
  border-width: 0 5px 5px !important;
}

.ts-wrapper.focus .ts-control,
.ts-wrapper.dropdown-active .ts-control {
  border-color: #6366f1 !important;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12) !important;
  background: #fff !important;
}

.ts-control > input {
  flex: 1 1 auto !important;
  width: auto !important;
  min-width: 0 !important;
  font-family: 'Cairo', system-ui, sans-serif !important;
  font-size: 13px !important;
  direction: rtl !important;
  text-align: right !important;
  color: #111827 !important;
  order: 1;
}

.ts-control .item {
  direction: rtl;
  text-align: right;
  color: #111827;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
  order: 1;
  padding: 0 !important;
  margin: 0 !important;
}

/* placeholder داخل الحقل — بدون تداخل */
.plugin-dropdown_input .ts-control .items-placeholder {
  flex: 1;
  min-width: 0;
  order: 1;
  text-align: right;
  color: #9ca3af;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
}

.ts-control .clear-button,
.ts-wrapper .clear-button {
  color: #9ca3af;
  margin-left: 4px;
}

/* Dropdown appended to body */
.ts-dropdown {
  direction: rtl !important;
  text-align: right !important;
  font-family: 'Cairo', system-ui, sans-serif !important;
  border: 1px solid #e2e6ed !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14) !important;
  z-index: 99999 !important;
  background: #fff !important;
  overflow: hidden;
}

.ts-dropdown .ts-dropdown-content {
  max-height: 240px;
  overflow-y: auto;
}

.ts-dropdown .option,
.ts-dropdown .no-results,
.ts-dropdown .create {
  padding: 10px 14px !important;
  font-size: 13px !important;
  cursor: pointer;
  text-align: right;
}

.ts-dropdown .option.active {
  background: #eef2ff !important;
  color: #4f46e5 !important;
}

.ts-dropdown .option:hover {
  background: #f8f9fb !important;
}

.ts-dropdown .no-results {
  color: #9ca3af;
  cursor: default;
}

/* Search box inside dropdown */
.ts-dropdown .dropdown-input-wrap {
  padding: 8px 10px !important;
  border-bottom: 1px solid #e2e6ed !important;
  background: #fff !important;
}

.ts-dropdown .dropdown-input {
  width: 100% !important;
  box-sizing: border-box !important;
  border: 1px solid #e2e6ed !important;
  border-radius: 6px !important;
  padding: 8px 12px !important;
  font-family: 'Cairo', system-ui, sans-serif !important;
  font-size: 13px !important;
  direction: rtl !important;
  text-align: right !important;
  outline: none !important;
  background: #f8f9fb !important;
}

.ts-dropdown .dropdown-input:focus {
  border-color: #6366f1 !important;
  background: #fff !important;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, .1) !important;
}

.ts-dropdown .dropdown-input::placeholder {
  color: #9ca3af;
}

/* Import/Export */
.io-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.io-bar .btn-io { padding: 8px 14px; font-size: 12px; }

.filter-actions,
.form-actions,
.card-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e2e6ed;
}

.card-header-row .card-title {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-header-row .card-title i { color: #4f46e5; font-size: 18px; }

@media (max-width: 768px) {
  .io-bar, .filter-actions .btn-io { width: 100%; justify-content: center; }
}
